Solved

PHP Mail Sending for Different Users

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

756 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