Link to home
Start Free TrialLog in
Avatar of IShiva
IShiva

asked on

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!

<?php
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "me@mydomain.com";
$Subject = "Tryout Form Submission";
$name = Trim(stripslashes($_POST['name']));
$comments = Trim(stripslashes($_POST['comments']));

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

// 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\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
ASKER CERTIFIED SOLUTION
Avatar of dutchclan
dutchclan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IShiva
IShiva

ASKER

Sorry for the delay in accepting dutchclan's answer. It worked perfectly!

IShiva