1

我已经实现了一个表单,可以成功地将提交的信息发送到我的电子邮件中。我可以通过除复选框之外的所有输入来实现这一点。我必须做什么才能使复选框值也出现在我的电子邮件中?我尝试为每个循环使用一个,但我不知道我是否沿着正确的路线。相关代码如下:

代码:

$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>
4

2 回答 2

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>
于 2012-12-12T14:43:51.193 回答
1

像这样试试。

if(!empty($_POST['check'])) {
    foreach($_POST['check'] as $value) {
        $check_msg .= "Checked:".$value."\n";            
    }}
于 2012-12-12T14:43:39.350 回答