我已经实施了一个表单,可以将提交的信息成功发送到我的电子邮箱。除了复选框之外,我可以通过所有输入实现此目的。为了使复选框值也出现在我的电子邮件中,我该怎么办?我试图为每个循环使用a但我不知道我是否沿着正确的路线。相关代码如下:
代码:
$companyname = $_POST['companyname'];
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$phonenumber = $_POST['phonenumber'];
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
$to = 'woodsy0130@hotmail.com';
$subject = 'Quote';
$message = 'Company Name: '.$companyname. "\n"."\n". 'Full Name: ' .$fullname. "\n"."\n". 'E-mail: '.$email. "\n"."\n". 'Phone Number: '.$phonenumber. "\n"."\n". 'Features: '$check_msg;
HTML:
<label><input type="checkbox" name="check[]" id="q12_1" value="E commerce Shopping Cart" />E-commerce (Shopping Cart)</label>
<label><input type="checkbox" name="check[]" id="q12_2" value="Content Management System CMS" />Content Management System (CMS)</label>
答案 0 :(得分:3)
尝试:
$message = 'Company Name: '.$companyname. "\n"."\n". 'Full Name: ' .$fullname. "\n"."\n". 'E-mail: '.$email. "\n"."\n". 'Phone Number: '.$phonenumber. "\n"."\n". 'Features: '.$check_msg;
您在.
'Features: '
例如,这有效:
<?php
$companyname = $_POST['companyname'];
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$phonenumber = $_POST['phonenumber'];
foreach ($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
$to = 'woodsy0130@hotmail.com';
$subject = 'Quote';
$message = 'Company Name: '.$companyname. "\n"."\n". 'Full Name: ' .$fullname. "\n"."\n". 'E-mail: '.$email. "\n"."\n". 'Phone Number: '.$phonenumber. "\n"."\n". 'Features: '.$check_msg;
echo $message;
?>
<form action='' method="post">
<label>
<input type="checkbox" name="check[]" id="q12_1" value="E commerce Shopping Cart" />
E-commerce (Shopping Cart)</label>
<label>
<input type="checkbox" name="check[]" id="q12_2" value="Content Management System CMS" />
Content Management System (CMS)</label>
<input type="submit" value="submit">
</form>
答案 1 :(得分:1)
试试这样。
if(!empty($_POST['check'])) {
foreach($_POST['check'] as $value) {
$check_msg .= "Checked:".$value."\n";
}}