Forum Moderators: coopster
When the form data is emailed, if more than one checkbox (each with a distinct name & value), is checked, the info output in the email of selections #2 and #3 are repeated 2 - 3 times. Other than that small glitch, everything works perfectly, emails go to the proper address, output in the email is formatted correctly.
Abbreviated code is below. I would appreciate any help with this!
FORM CODE SNIPPET
<input type="checkbox" name="city0" value="CryC">
<input type="checkbox" name="city1" value="CH">
<input type="checkbox" name="city2" value="OB">
$CryC = $_POST['city0'];
$CH = $_POST['city1'];
$OB = $_POST['city2'];$if ($formname == "accom" && isset($CryC))
{ $SendTo = "CryC-Accom@domain.com";
$SubjectLine = "CRYSTAL COAST $formname Lead from\n";
//variable processing//
include 'fprocessA.php';
// Send E-Mail //
if (count($_POST)!= 0)
{
$Spam = false;
foreach ($_POST as $Field=>$Value)
{
$Spam = $Spam ¦¦ stristr($Value, "bcc: ");
}
if (!$Spam)
{
$mailheaders = "From: $SendFrom \r\n";
$mailheaders .= "Reply-To: $Reply_To \r\n";
mail($SendTo, $SubjectLine, $MsgBody, $mailheaders);
}
}
}
if ($formname == "accom" && isset($CH))
{ $SendTo = "CH-Accom@domain.com";
$SubjectLine = "CHARLESTON SC $formname Lead from\n";
include 'fprocessA.php';
// Send E-Mail //
if (count($_POST)!= 0)
{
$Spam = false;
foreach ($_POST as $Field=>$Value)
{
$Spam = $Spam ¦¦ stristr($Value, "bcc: ");
}
if (!$Spam)
{
$mailheaders = "From: $SendFrom \r\n";
$mailheaders .= "Reply-To: $Reply_To \r\n";
mail($SendTo, $SubjectLine, $MsgBody, $mailheaders);
}
}
}
if ($formname == " accom" && isset($OB))
{ $SendTo = "OB-Accom@domain.com";
$SubjectLine = "NC OUTER BANKS $formname Lead from\n";
include 'fprocessA.php';
// Send E-Mail //
if (count($_POST)!= 0)
{
$Spam = false;
foreach ($_POST as $Field=>$Value)
{
$Spam = $Spam ¦¦ stristr($Value, "bcc: ");
}
if (!$Spam)
{
$mailheaders = "From: $SendFrom \r\n";
$mailheaders .= "Reply-To: $Reply_To \r\n";
mail($SendTo, $SubjectLine, $MsgBody, $mailheaders);
}
}
}
$MsgBody .= "Arrival Date: $Arrival_Date\n";
$MsgBody .= "Nights: $nights\n\n";if (isset($_POST['accom_type']))
{
foreach ($_POST['accom_type'] as $accom_value) {$MsgBody .= "Requested Accommodations Type: $accom_value\n";}
}
$MsgBody .= "$Divider\n" . "Visitor IP Address:" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe
There must be a loop somewhere that's misbehaving but I don't see any issues with what's up here now.
How does the value of the three variables in question affect $MsgBody.
What is should be doing is when it hits one of the if statements and that checkbox is checked, emails the form info to the address designated. Just one copy of the info, not multpiles in one email.
ABBREVIATED OUTPUT:
Address 1: TEST 4
Address 2: TEST 4
City: TEST 4
State: TEST 4
Address 1: TEST 4
Address 2: TEST 4
City: TEST 4
State: TEST 4
Address 1: TEST 4
Address 2: TEST 4
City: TEST 4
State: TEST 4
I've got a hunch the issue is with the checkboxes, though. I would try to narrow things down by substituting the three checkboxes with textfields and then modifying the conditionals to:
if ($formname == "accom" && $CH == 'yes'))
where you'll type "yes" into each textfield you want to send.
If error still occurs the issue is elsewhere... but I bet it's not.
fprocessA assembles the email. The output comes as an email.
$MsgBody .= "Arrival Date: $Arrival_Date\n";
$MsgBody .= "Nights: $nights\n\n";
if (isset($_POST['accom_type']))
{
foreach ($_POST['accom_type'] as $accom_value) {$MsgBody .= "Requested Accommodations Type: $accom_value\n";}
}
$MsgBody .= "$Divider\n" . "Visitor IP Address:" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe
I'm beginning to think the problem lies in my foreach loops, since they are the only looping structures I'm using.
if ($formname == "Accommodations" && isset($CryC))
{ $SendTo = "ng-CryC-Accom@domain.com";
$SubjectLine = "NC CRYSTAL COAST $formname Lead from domain\n";
include 'fprocessA.php';
}if ($formname == "Accommodations" && isset($CH))
{ $SendTo = "ng-CH-Accom@domain.com";
$SubjectLine = "CHARLESTON SC $formname Lead from domain\n";
include 'fprocessA.php';
}
if ($formname == "Accommodations" && isset($OB))
{ $SendTo = "ng-OB-Accom@domain.com";
$SubjectLine = "NC OUTER BANKS $formname Lead from domain\n";
include 'fprocessA.php';
}
$MsgBody .= "Name: $name\n";
$MsgBody .= "Email: $email\n";
$MsgBody .= "Company: $Company\n";
$MsgBody .= "Address 1: $Address1\n";$MsgBody .= "\n";
if (isset($_POST['amenities']))
{
foreach ($_POST['amenities'] as $amenity_value) {$MsgBody .= "Requested Amenities: $amenity_value\n";}
}
$MsgBody .= "$Divider\n" . "Visitor IP Address:" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe
$mailheaders = "From: $SendFrom \r\n";
$mailheaders .= "Reply-To: $Reply_To \r\n";
mail($SendTo, $SubjectLine, $MsgBody, $mailheaders);
The only foreach loops that remain are in the formation of the email in $MsgBody. The spam filtering loops have been moved to earlier in the page. Yet, it still send duplicate info in the emails.