Link to home
Start Free TrialLog in
Avatar of JiveMedia
JiveMediaFlag for Australia

asked on

PHP Mail Sending for Different Users

Hi,

I have made a pretty simple php booking form that gets sent to the client as well as the person that used the form to make the booking.

I have the usual toaddress, subject, message, fromaddress in the mail function.
mail($toaddress, $subject, $strMessageBody, $fromaddress);
mail($email, $subject, $strMessageBody, $fromaddress);

Open in new window


I now need to send the full copy to the client and a limited version to the user excluding some variables (ie. payment details).

Was wondering the best way to go about this?

Many thanks.
Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

try like this,

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

Probably most of the information you want to provide or redact is contained in the variable named $strMessageBody.  This is a PHP string variable.  You might want to go into the PHP code that processes the form submission.  Follow the variables from the request ($_GET or $_POST) and see how the script uses them to construct $strMessageBody.  You would probably want to create two versions of that variable.  One would contain everything and the other would simply omit the things that you did not want to expose to another party.
I do this all the time on several sites.  As I process the form info, I create two different versions, one with all the info and one with only part of it.  Then I send the different versions to different places.
ASKER CERTIFIED SOLUTION
Avatar of vid_yag
vid_yag
Flag of India 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