Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP Mail Sending for Different Users

Posted on 2013-05-27
4
Medium Priority
?
264 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
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 111

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 84

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

773 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