Laurens van Vliet Laurens van Vliet - 1 year ago 49
HTML Question

html and php form not sending / sending empty mails

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.


<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">
<div class="error-message">
<p>Vul een geldig e-mailadres in</p>

<div class="icon">
<label class="cd-label">Naam</label>
<input class="user" type="text" name="cd-name" id="cd-name" required>

<div class="icon">
<label class="cd-label">Bedrijf</label>
<input class="company" type="text" name="cd-company" id="cd-company">

<div class="icon">
<label class="cd-label">Email</label>
<input class="email" type="email" name="cd-email" id="cd-email" required>

<div> </div>
<div class="icon">
<label class="cd-label">Bericht</label>
<textarea class="message" name="cd-textarea" id="cd-textarea" required></textarea>

<input type="submit" value="Verzenden">



$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";

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download