Solved

PHP Mail Sending for Different Users

Posted on 2013-05-27
4
254 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 108

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 82

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now