我在使用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 = "[email protected]";
$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>
当我收到的电子邮件,有时只显示 “摘心 - ,,,,?”。
真的需要这方面的帮助和任何建议将不胜感激!
谢谢!
有什么模式,当它是空的? – maxhud 2012-07-10 19:30:26
如果某人没有选择任何复选框作为顶点会发生什么?是否有验证停止,或者它是一个有效的选择? – andrewsi 2012-07-10 19:37:07
这不是很好的HTML。另外,你为什么用一个子串方法包装内爆输入? – 2012-07-10 19:40:09