获得多个复选框的价值&回复电子邮件

时间:2014-04-21 08:36:08

标签: php email checkbox

由于我对PHP的了解不足,在邮件正文中添加多个复选框值时遇到了麻烦。

我知道可以通过带有echo循环的数组显示/ foreach复选框,但我不知道邮件正文中的echo。我想在$message内回应它。

HTML代码示例 -

<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代码 -

<?php

$to = "arifkpi@gmail.com";
$fromEmail = "arif@arif-khan.net";
$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 个答案:

答案 0 :(得分:2)

你可以这样做,

$colors = isset($_POST['color']) ? implode(",",$_POST['color']) : '';

现在,您可以在电子邮件正文部分中使用此$colors(您将选择所有选定的颜色作为逗号分隔)。

$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]";

答案 1 :(得分:0)

试试这个

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