PHP Contact Form With Automatic Thank You Reply

 

I have provided you with the form itself and the php script which will send the form.

This PHP script, will collect all data from the form and send it to you. It will also send an email to the person who filled in the form (a thank you email)

 

Example







 

Script Source

<The Form >

<form action="#" method="post" name="FormName" id="FormName">
<label for="name">Name:</label>
<br />
<input type="text" id="name" name="name" size="50" />
<br />
<label for="email"> Email:</label>
<br />
<input type="text" id="email" name="email" size="50" />
<br />
<label for="username"> Username:<br />
</label>
<input type="text" id="username" name="username" size="50" />
<br />
<label for="questions"> Question or Comment:</label>
<p><br />
<textarea id="questions" name="comment" rows="10" cols="50"></textarea>
</p>
<p><input type="submit" name="Submit" value="Submit" />
</form>

<The script to send the data input >

<?php

$username = $_POST['name'];
$useraddress = $_POST['email'];
$site = "yoursite.co.uk";
$body = "This person has sent a message to your site\n\n";

foreach($_POST as $field => $value) {

$body .= sprintf("%s = %s\n", $field, $value);
}

mail("youraddress@yourdomain.co.uk", "Contact form", $body, 'From: "your site" <youraddress@yourdomain.co.uk>');

mail("$useraddress", " Thanks for your message",
"Hi $username,\n
Thank you for your message. We will be in contact if you require us to do so.\n
Why not subscribe to (yoursite.co.uk) https://www.yoursite.co.uk", 'FROM: "Your site" <yoursite.co.uk>');

?>

<h1>Thank You</h1>
Your Message has been sent!

 

Please let me know if this script was helpful to you.

[rating]