Reputation: 61
So I have this small html form, now I wanted to use php to send rhe data to a e-mail. for the form i used a template I changed a few names. 1 time it send an email but it was empty, from all the other tries I don't get a mail at all. from searching the internet I get that I've done nothing wrong, checked names and all.
html:
<div id="contact">
<h1>Neem contact met ons op</h1>
<form class="cd-form floating-labels" action="form_sent.php" method="post" enctype="text/plain">
<fieldset>
<div class="error-message">
<p>Vul een geldig e-mailadres in</p>
</div>
<div class="icon">
<label class="cd-label">Naam</label>
<input class="user" type="text" name="cd-name" id="cd-name" required>
</div>
<div class="icon">
<label class="cd-label">Bedrijf</label>
<input class="company" type="text" name="cd-company" id="cd-company">
</div>
<div class="icon">
<label class="cd-label">Email</label>
<input class="email" type="email" name="cd-email" id="cd-email" required>
</div>
</fieldset>
<fieldset>
<div> </div>
<div class="icon">
<label class="cd-label">Bericht</label>
<textarea class="message" name="cd-textarea" id="cd-textarea" required></textarea>
</div>
<div>
<input type="submit" value="Verzenden">
</div>
</fieldset>
</form>
</div>
php:
<?php
$user = $_POST['cd-user'];
$company = $_POST['cd-company'];
$email = $_POST['cd-email'];
$message = $_POST['cd-textarea'];
$to = "[email protected]";
$subject = "Website bericht";
mail ($to , $subject , $message, "From: " , $user , $company , $email);
echo "Bedankt voor uw bericht";
?>
Upvotes: 1
Views: 45
Reputation: 9937
You are passing the wrong arguments to mail(). It expects 5, 2 of them optional:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
In your case, I think the last 3 parameters are only one, so do this:
$userInfo = $user." ".$company." <".$email.">";
mail ($to , $subject , $message, "From: ".$userInfo);
Also, for $user you're getting $_POST["cd-user"], but the input name
is cd-name
, not cd-user
--
The problem ended up being that PHP can't handle enctype="text/plain", so removing it fixed it.
Upvotes: 2