0

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";
}
?>

2 Answers 2

2

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]";
Sign up to request clarification or add additional context in comments.

9 Comments

how can i implement it with $message, i want it in mail body. Thanks
see my updated answer, I have added $colors in message body.
Parse error: syntax error, unexpected '=' in /home/arifkpi/public_html/arif/project/cform/form_action.php on line 8 Line 8- $color= isset($_POST['color']) = implode(", ",$_POST['color']) : '';
Just update but new error, Warning: implode(): Invalid arguments passed in /home/arifkpi/public_html/arif/project/cform/form_action.php on line 8
Can you post output of $_POST['color'] ?
|
0

Try this

if(isset($_POST['color'])) {
    $message.= implode(',', $_POST['color']);
} 

1 Comment

Warning: implode(): Invalid arguments passed in /home/arifkpi/public_html/arif/project/cform/form_action.php on line 22 Your code is on line 22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.