2 Emails Sent From Contact Form: 1 to Admin + 1 to User

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jimmel3215
Forum Newbie
Posts: 1
Joined: Tue Apr 24, 2007 11:25 am

2 Emails Sent From Contact Form: 1 to Admin + 1 to User

Post by jimmel3215 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello!  I'm a designer so I'm not very good at programming or PHP so any help you can give me is appreciated.  

Currently I have a contact form that sends an email to me when someone submits it.  Everything with it is functioning properly.  What I would like is an email to also be generated and sent to the person who submitted the form.  I would like it to take their first and last name from the form fields and insert it into the email as well.  So the email sent to the user after they his submit would say something like "Thank [u]John[/u] [u]Doe[/u] for filling out the form.  Expect to hear from me shortly."  My current PHP code looks like the following:

Code: Select all

<?php

// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['Email'])); 
$EmailTo = "jimmel@trendyminds.com";
$Subject = "contact form submission"; 
$FirstName = Trim(stripslashes($_POST['FirstName'])); 
$LastName = Trim(stripslashes($_POST['LastName'])); 
$Tel = Trim(stripslashes($_POST['Tel'])); 
$Email = Trim(stripslashes($_POST['Email'])); 


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

// prepare email body text
$Body = "";
$Body .= "First Name: ";
$Body .= $FirstName;
$Body .= "\n";
$Body .= "Last Name: ";
$Body .= $LastName;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;

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

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

You can either CC to your admin account, or have another mail() call pointing to your admin email.
Post Reply