bmccarthy Posted January 8, 2013 Share Posted January 8, 2013 Hello, Something is wrong with the below php code that allows the form to send to three separate recipients with three separate messages. Something in the below code is causing recipients A's email to come through just fine. The problem is that recipient B receives A's message as well as their message and recipient C to receive A's and B's message as well as their message. (I hope that makes sense!). Note: I have changed some of the text for anonymity purposes. I'm sure I'm missing something simple that closes/ends the first email but I'm not sure what. Please help. Thanks! <?php $to = 'me@domain'; $subject = 'subject line'; $url = 'http://www.domain.com/confirmation.html'; $headers .= "From: info@domain.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $message .= '<html><body>'; $message .= " "; $message .= " "; $message .= "<strong>Referral</strong></br>"; $message .= "The following information has been submitted by " . strip_tags($_POST['submitter']) . " with ID " . strip_tags($_POST['MID']) . " on " . strip_tags($_POST['Today']) . ".</br>"; $message .= "Please reach out to the following referral:</br>"; $message .= "Name: " . strip_tags($_POST['name']) . ".</br>"; $message .= "Contact Phone: " . strip_tags($_POST['phone']) . ".</br>"; $message .= "Email Address: " . strip_tags($_POST['email']) . ".</br>"; $message .= "</br>"; $message .= "</br>"; $message .= "</br>"; $message .= "Thank You!"; mail($to, $subject, $message, $headers); $to = $_POST['semail']; $subject = 'Thank you for your submission!'; $headers .= "From: info@domain.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $message .= '<html><body>'; $message .= " "; $message .= " "; $message .= "Dear " . strip_tags($_POST['submitter']) . ",</br>"; $message .= "Thank you for your submission! </br>"; $message .= "We will reach out to " . strip_tags($_POST['name']) . " per your referral. </br>"; $message .= "</br>"; $message .= "We appreciate your time and thank you for your support!"; $message .= "</br>"; $message .= "Have a great day,"; mail($to, $subject, $message, $headers); $to = $_POST['email']; $subject = "" . strip_tags($_POST['submitter']) . " wanted us to call you!</br>"; $headers .= "From: info@domain.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $message .= '<html><body>'; $message .= " "; $message .= " "; $message .= "Dear " . strip_tags($_POST['name']) . ",</br>"; $message .= "Recently, " . strip_tags($_POST['submitter']) . " provided us with your information because they wanted to let you know about the great experience they have had with our company and how you could benefit from the services they currently use.</br>"; $message .= "We are sending this email to confirm your contact information. One of our expert Account Service representatives will be reaching out to you at " . strip_tags($_POST['phone']) . " shortly to discuss the services we can offer to your company.</br>"; $message .= "</br>"; $message .= "We appreciate your time and look forward to speaking with you!"; $message .= "</br>"; $message .= "Have a great day,"; mail($to, $subject, $message, $headers); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> Quote Link to comment Share on other sites More sharing options...
Love2c0de Posted January 8, 2013 Share Posted January 8, 2013 (edited) After sending each email, do this: $message = ""; This will clear the $message variable and set it to an empty string. The reason it was sending the emails was because you are concatenating the $message variable all the way through the script so it's literally just adding the other email to the end of the string for the first email. Regards, L2c. Edited January 8, 2013 by Love2c0de Quote Link to comment Share on other sites More sharing options...
bmccarthy Posted January 11, 2013 Author Share Posted January 11, 2013 @L2c, Thanks! Works perfectly. Quote Link to comment Share on other sites More sharing options...
DavidAM Posted January 12, 2013 Share Posted January 12, 2013 You may want to do the same with $headers. As it is, you are adding another set of headers for each subsequent message. If you (later) add something specific to the headers of one email, it will carry to the next. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.