Reputation: 750
Getting trouble on adding multiple checkbox value within mail body due to my low knowledge in PHP.
I know that it possible to show/echo
checkbox by array with foreach
loop but i don't know to echo
it within mail body. I want to echo it within $message
.
HTML Code sample-
<input type="checkbox" name="color[]" value="Value1"> Title1
<input type="checkbox" name="color[]" value="Value2"> Title2
<input type="checkbox" name="color[]" value="Value3"> Title3
<input type="checkbox" name="color[]" value="Value4"> Title4
<input type="checkbox" name="color[]" value="Value5"> Title5
PHP Code-
<?php
$to = "[email protected]";
$fromEmail = "[email protected]";
$fromName = "Arif Khan";
$subject = "Contact Email";
$message = "Hey, Someone Sent you a Contact Message through your Website.
Details Below-
Name: $_POST[fname] $_POST[lname]
Email Address: $_POST[email]
Contact Number: $_POST[contact1] $_POST[contact2] $_POST[contact3]
Zip Code: $_POST[zip]
Best Time To Contact: $_POST[besttime]
Payment Plan Options: $_POST[payment_plan]
MUA: $_POST[mua]
Shoot Concept:
Shoot Concept(Other): $_POST[shootother]";
$headers = "From:" . $fromName . " " . $fromEmail;
$flgchk = mail ("$to", "$subject", "$message", "$headers");
if($flgchk){
echo "A email has been sent to: $to";
}
else{
echo "Error in Email sending";
}
?>
Upvotes: 0
Views: 144
Reputation: 100
Try this
if(isset($_POST['color'])) {
$message.= implode(',', $_POST['color']);
}
Upvotes: 0
Reputation: 26431
You can simply do,
$colors = isset($_POST['color']) ? implode(",",$_POST['color']) : '';
And now you can use this $colors
(you will get all selected colors as comma separeted) in your email message body part.
$message = "Hey, Someone Sent you a Contact Message through your Website.
Details Below-
Name: $_POST[fname] $_POST[lname]
Colors: $colors
Email Address: $_POST[email]
Contact Number: $_POST[contact1] $_POST[contact2] $_POST[contact3]
Zip Code: $_POST[zip]
Best Time To Contact: $_POST[besttime]
Payment Plan Options: $_POST[payment_plan]
MUA: $_POST[mua]
Shoot Concept:
Shoot Concept(Other): $_POST[shootother]";
Upvotes: 2