我目前正在处理此订单:http ://www.libertydelimart.com/order
现在,所有项目都会发布到我的电子邮件中——无论天气如何,信息都已输入到“多少”文本框中。
排除在“多少”文本框中没有输入任何内容的项目的最佳方法是什么,以便只有输入了信息的项目才会通过电子邮件发送给我?
<?php
if(isset($_POST['submit'])) {
$to = "test@mywebsite.com";
$subject = "New Order";
$name_field = $_POST['name'];
$phone_field = $_POST['phone'];
$food = $_POST['food'];
$body = 'Name: ' . $name_field . PHP_EOL . 'Phone: ' . $phone_field . PHP_EOL;
//Check if any food items were set in order to prevent foreach error
if($food){
foreach ($food as $key => $item) {
$body .= $key . ' - ' . $item ['how_many'];
if($item['customize']) $body .= ' ('.$item['customize'].')' . PHP_EOL;
}
}
echo "Your Order Will Be Ready In 30 Minutes!";
mail($to, $subject, $body,"FROM: Deli <$to>");
print '<pre>'.$body.'</pre>';
}
?>