Jump to content

Need Quick Help with Form Handler


bmccarthy

Recommended Posts

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 .= "&nbsp";
$message .= "&nbsp";
$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 .= "&nbsp";
$message .= "&nbsp";
$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 .= "&nbsp";
$message .= "&nbsp";
$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.'">';
?>

Link to comment
Share on other sites

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 by Love2c0de
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.