• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

PHP mail question

Hi, I was wondering if it is possible to add 2 mail features into a script. I have it now where the script sends an email to me when the form is submitted. I would like it to also send a confirmation back to the person who sent it. Please advise. Thank you.
//sends email via php to the following address
$mailuser = "email@emailhere.com";
$replyuser = $_POST['email'];
$replyname = $_POST['name'];
//echo 'default chosen address: '.$mailuser;
	$header = "Return-Path: ".$mailuser."\r\n"; 
	$header .= "From: ".$replyname." <".$replyuser.">\r\n"; 
	$header .= "Content-Type: text/html;"; 
	$interests ="";
      $list = $_POST['interests'];
      foreach($list as $k => $v)
      $interests .= $v . "<br />\n";
	$mail_body = '
	'. $_POST[name] . ' has submitted this information from the Equine Reproduction Concepts website. <br><br>
	Name: '. $_POST[name] . '<br>
	email: '. $_POST[email] . '<br>
	Address: '. $_POST[address] . '<br>
	City: '. $_POST[city] . '<br>
	State: '. $_POST[state] . '<br>
	Zip Code: '. $_POST[zip] . '<br>
	Home Phone Number: '. $_POST[hphone] . '<br>
	Work Phone Number: '. $_POST[wphone] . '<br>
	Fax Number: '. $_POST[fax] . '<br>
	Comments/Questions: '. $_POST[notes] . '<br><br>'. ($interests!="" ?'
      Interests: All of the below were checked as services '. $_POST[name] . ' has interest in.<br> '. $interests : '');
	mail ($mailuser, 'ERC Contact Submission', $mail_body, $header);

Open in new window

1 Solution
Should be able to do it just by changing to this

$mailuser = "email@emailhere.com,".$_POST['email'];
Or, you could add another mail() function right below your current that says this, if you want:

mail ($_POST['email'], 'ERC Contact Submission Confirmation', $mail_body, $header);

There are actually several ways to do it
You might want to create a new $header for the response email - otherwise  the confirmation mail to the user will appear to come from the user themselves.
I suggest using a PHP-Mailer-Class like http://phpmailer.sf.net or http://swiftmailer.sf.net which will allow you to extend your script easy and understandable. Also it will protect you script agains Mail_injects and thus acting your server as a spammer which is currently possible with that script.
Loganathan NatarajanLAMP DeveloperCommented:
this is very good example, just try for multiple recipients,
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
  <title>Birthday Reminders for August</title>
  <p>Here are the birthdays upcoming in August!</p>
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);

Open in new window


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now