我在使用 php 邮件功能发送 html 表单的数据时遇到了一些问题。邮件功能工作正常,提交表单时接收电子邮件没有问题,但有时我的电子邮件中有空数组。
代码如下所示:
<?php
error_reporting(E_ALL & ~E_NOTICE);
$email = $_POST['email'];
//check if value is set:
if (isset($_POST['submit'])){
$everyoneToppingList = substr(implode(', ', $_POST['everyone_platter_topping']), 0);
$everyoneCondimentList = substr(implode(', ', $_POST['everyone_platter_condiment']), 0);
}; //end isset($_POST['submit']
$len = strlen($email);
if ($len > 0)
{
$email_body = "Full Name: $title $fullname\n".
"Topping? - $everyoneToppingList\n".
"Condiment? - $everyoneCondimentList\n\n";
$email_to = "example@gmail.com";
$email_from = $_POST['email']; // required
$URL= "order.php";
header ("Location: $URL");
// create email headers
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email_from \r\n";
$headers .= "Cc: $email_from \r\n";
$headers .= "X-Mailer: PHP/". phpversion();
mail($email_to, $email_subject, $email_body, $headers);
} ?>
html部分看起来像:
<table style="vertical-align:top;" class="form platter bread" cellspacing="2">
<tr>
<span class="bold">
Choose Your Topping:
</span>
<span id="errorsDiv_everyone_platter_topping[]">
</span>
<td height="7" width="87" align="left" valign="middle">
<input type="checkbox" name="everyone_platter_topping[]" value="Lettuce" id="everyone_lettuce" />
<label for="everyone_lettuce">\
Lettuce
</label>
</td>
<td height="7" width="87" align="left" valign="middle">
<input type="checkbox" name="everyone_platter_topping[]" value="Tomatoes" id="everyone_tomatoes" />
<label for="everyone_tomatoes">
Tomatoes
</label>
</td>
</tr>
</table>
当我收到电子邮件时,有时它只显示“Topping? - , , , , , 。
真的需要帮助,任何建议都将不胜感激!
谢谢!