Link to home
Start Free TrialLog in
Avatar of pertrai1
pertrai1

asked on

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

Avatar of darron_chapman
darron_chapman
Flag of United States of America image

Should be able to do it just by changing to this

$mailuser = "email@emailhere.com,".$_POST['email'];
ASKER CERTIFIED SOLUTION
Avatar of darron_chapman
darron_chapman
Flag of United States of America image

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 almilyo
almilyo

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.
Avatar of Loganathan Natarajan
this is very good example, just try for multiple recipients,
<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';
 
// subject
$subject = 'Birthday Reminders for August';
 
// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';
 
// 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