I am working on the contact form on a webpage. The HTML and CSS is complete, how it supposed to be. However, now I need to make this button work so it sends an e-mail to the given e-mail address. I am a newbie in PHP, so hope someone could help me out.
HTML code:
<div id="thirdColumn">
<div id="contactOns">
<form action="send.php" method="post" enctype="text/plain" class="form">
<p class="name">
<input type="text" name="name" id="name" placeholder="NAAM" />
</p>
<p class="email">
<input type="text" name="email" id="email" placeholder="EMAIL" />
</p>
<p class="text">
<textarea name="text" name="message" id="message" placeholder="BERICHT"></textarea>
</p>
<p class="submit">
<input type="submit" id="sent" value="VERSTUUR" />
</p>
</form>
</div> <!-- End contactOns -->
</div> <!-- End thirdColumn -->
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mail_to = 'riksterrr@gmailc.com';
$subject = 'Bericht van een bezoeker '.$name;
$body_message = 'From: '.$name."
";
$body_message .= 'E-mail: '.$email."
";
$body_message .= 'Message: '.$message;
$headers = 'From: '.$email."
";
$headers .= 'Reply-To: '.$email."
";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
?>
2 things that needed to be changed in your HTML form are, get rid of enctype="text/plain"
and change:
<textarea name="text" name="message" id="message" placeholder="BERICHT"></textarea>
to:
<textarea type="text" name="message" id="message" placeholder="BERICHT"></textarea>
You had name="text"
which should be type="text"
Since you do not have your own Web server setup with PHP, you will need to find a hosting company that has mail()
available in order to run your code properly.