Form to email but also with 'thank you' email to user

Hey guys and gals

I have very little php experience so your help is greatly appreciated. I have a php script that sends an email to us when someone fills out our online form.

I would like to also send a 'Thank You' email to the user that just filled out the form. Can you add some code to what Ive got to accomplish this?

Thanks so much!

$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "";
$Subject = "Tryout Form Submission";
$name = Trim(stripslashes($_POST['name']));
$comments = Trim(stripslashes($_POST['comments']));

// validation
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $comments;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=ThankYou.html\">";
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
Who is Participating?
dutchclanConnect With a Mentor Commented:
Oke a little help on your hand :D

First lets think out the logic.

If someone loads the page, we want them to see the form. Then if the form was send but we missed values we show the form again with notifications on the fields not filled out or not passing the a validation of another kind. If all validations succeed we then process the from and send a "thank you" mail.

if(isset($_POST['submit']) ){
          // Validate fields  do this with all the named fields in the form (especially the email addr)//
          if(isset($_POST['name']) ){
                 if(!empty($_POST['name']) ){
                       if(strlen($_POST['name']) >= 3){
                               $error_msg .= "Name to short<br>\n";
                      $error = true;
                      $error_msg .= "No name given<br>\n";
                  $error = true;
                  $error_msg .= "No Name Set<br>\n";

           if($error == false){     // Validation using equal to is done by the dubble equal to sign " == "
                   $to = $_POST['user_email'];
                   $subject = "thank you";
                   // Setting email headers
                   $headers  = 'MIME-Version: 1.0' . "\r\n";
                   $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                   $headers = "From:\r\n";
                   $headers .= "Reply-To:\r\n";
                   $headers .= "Return-Path:\r\n";
                   // Create a nice message "html"//
                   $body = '<table width="80%" cellspacing="0" cellpadding="0">\n
                                             <td>Thank you for your application</td>\n
                                             <td><div>Some nice message to '.$_POST['name'].' and somehow
                  if(mail($to, $subject, $body, $headers) ){

// Assign all filled out fields if any.
$name = (isset($_POST['name']) ) ? $_POST['name'] : "";
$error = ($error == true) ? "Error occured" : "&nbsp;";

// Then show the form.

<form action="'.$_SERVER['PHP_SELF'].'" method="post">
      <td><input type="text" name="name" value="'.$name.'"></td>
      <td><input type="submit" name="submit"></td>

Please look at it and question the code if you dont get it... ;) good luck!
IShivaAuthor Commented:
Sorry for the delay in accepting dutchclan's answer. It worked perfectly!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.