由于我对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";
}
?>
答案 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']);
}