Solved

PHP Mail Sending for Different Users

Posted on 2013-05-27
4
259 Views
Last Modified: 2013-05-31
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.
0
Comment
Question by:JiveMedia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 39200360
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

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39200361
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.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39200458
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.
0
 
LVL 2

Accepted Solution

by:
vid_yag earned 500 total points
ID: 39200863
You need to divide your email content into different sections / variables.
Different variables may like:
$strMailHeader = '<Mail Header content goes here>';
$strMailFooter = '<Mail Footer content goes here>';
$strMailGeneralContent = '<Mail General content goes here>';
$strMailPaymentDetailsContent = '<Mail Payment Details content goes here>';

Open in new window

Now you can create two different email versions with these variables.
To Client: (Full Email)
$strClientMessageBody = $strMailHeader.$strMailGeneralContent.$strMailPaymentDetailsContent.$strMailFooter;
mail($clientEmailAddres, $subject, $strClientMessageBody, $fromaddress);

Open in new window

To User: (Limited Email)
$strUserMessageBody = $strMailHeader.$strMailGeneralContent.$strMailFooter;
mail($userEmailAddres, $subject, $strUserMessageBody, $fromaddress);

Open in new window

0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question