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)




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 />
<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><input type="submit" name="Submit" value="Submit" />

<The script to send the data input >


$username = $_POST['name'];
$useraddress = $_POST['email'];
$site = "";
$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("", "Contact form", $body, 'From: "your site" <>');

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 (", 'FROM: "Your site" <>');


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


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