Using PHP To Send Contact Form Confirmation Emails




Send Your Contact Form Users a Message or Confirmation

By following the first 2 little articles you now have a simple form to collect an email address from your visitors, process the form with PHP and email you the data.  But what if you want to send your visitor a confirmation email? The easiest  way to do this is simply create another area of your code to send them the message like this.

$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you@youremailaddress.com\n";

$usermessage = "Thank you for subscribing to our mailing list.";

Then set the code to mail that information.

mail($user,$usersubject,$usermessage,$userheaders);

So here is the full code for the "process.php" page to take the text field of your form, convert to php, and send the data to your email AND send confirmation to your user.

<?PHP
$email = $_POST["emailaddress"];

$to = "you@youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";

$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n

Email Address: $email";

$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you@youremailaddress.com\n";

$usermessage = "Thank you for subscribing to our mailing list.";

mail($to,$subject,$message,$headers);

mail($user,$usersubject,$usermessage,$userheaders);

?>

 

Previous   |  Next

Special Package Offer

    Discounted deal on all of our php contact form scripts as a bundle package