【问题标题】:Checkbox value not appearing in email复选框值未出现在电子邮件中
【发布时间】:2012-08-14 10:17:07
【问题描述】:

我创建了一个通过电子邮件提交详细信息的表单,但由于某种原因,复选框结果没有显示,任何人都可以看到原因吗?

<tr>
  <td valign="top"><p>Contact Method:</p></td>
  <td>&nbsp;</td>
  <td align="left" valign="top"><p>
      <input style="width:20px!IMPORTANT;" type="checkbox" name="CheckboxGroup1[]" value="Phone" id="phone" />
      <label style="margin-right: 25px;">Phone</label>
    </p>
    <p>
      <input style="width:20px!IMPORTANT;" type="checkbox" name="CheckboxGroup1[]" value="Email" id="email" />
      <label style="margin-right: 25px;">Email</label>
    </p>
    <p>
      <input style="width:20px!IMPORTANT;" type="checkbox" name="CheckboxGroup1[]" value="Post" id="post" />
      <label style="margin-right: 25px;">Post</label>
    </p></td>
</tr>

然后我用这个来提交:

<? if(isset($_POST['submit'])) { 

$to = "rob@domain.com";
$header = 'From: info@domain.com';
$subject = "Website enquiry";
$companyname_field = $_POST['companyname'];
$fullname_field = $_POST['fullname'];
$email_field = $_POST['email'];
$tel_field = $_POST['tel'];
$address_field = $_POST['address'];
$specify_field = $_POST['specify'];
$CheckboxGroup1 = $_POST['CheckboxGroup1'];
$CheckboxGroup2 = $_POST['CheckboxGroup2'];
if( is_array($_SESSION['CheckboxGroup1']) ){
    foreach ($_SESSION['CheckboxGroup1'] as $val) {
        $checkbox1results .= $val.",\n";
    }
}
if( is_array($_SESSION['CheckboxGroup2']) ){
    foreach ($_SESSION['CheckboxGroup2'] as $val) {
        $checkbox2results .= $val.",\n";
    }
}


$body = "Hello,\n\n You have an enquiry from the website, please see the details below:\n\n Name: $fullname_field\n Company Name: $companyname_field\n E-Mail: $email_field\n Tel: $tel_field\n Method of contact: $checkbox1results\n Address: $address_field\n Hear about us?: $checkbox2results\n Specify: $specify_field\n\n Please reply to the enquiry asap.\n\n Kind Regards \n";

mail($to, $subject, $body, $header);

echo "</br><p style=\"color:#e41770!IMPORTANT;\">Thank you for getting in touch, we will contact you shortly.</p>";

} ?>

【问题讨论】:

  • 据我所知,表单、输入、css、javascript 和大多数 HTML 代码最常被电子邮件客户端删除。

标签: php html forms checkbox


【解决方案1】:

$_SESSION['CheckboxGroup1'] 在哪里声明?看到你的代码应该是$_POST['CheckboxGroup1']

【讨论】:

    【解决方案2】:

    您从$_POST 中获取值,但您检查$_SESSION 中的值。

    【讨论】:

      【解决方案3】:

      改用该代码

      if( is_array($CheckboxGroup1) ){
      foreach ($CheckboxGroup1 as $val) {
          $checkbox1results .= $val.",\n";
       }
      }
      if( is_array($CheckboxGroup2) ){
         foreach ($CheckboxGroup2 as $val) {
          $checkbox2results .= $val.",\n";
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-08
        • 2020-09-05
        • 2011-01-27
        • 2013-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多