您好我首先要说的是我更像是设计师而不是开发人员。
我正在为包含200种不同食物类型的餐厅创建食物清单。
HTML下面的:
<form name="htmlform" method="post" action="send.php">
<table class="hoverTable" width="300">
<tr><td><strong>CANAPES</strong></td><td></td></tr>
<tr><td width="200" >email</td><td><input name="email"type="text" style="width:200px;" placeholder="Qty"/></td></tr>
<tr><td width="200" >Caviar:Black & red</td><td><input name="Caviar"type="text" style="width:50px;" placeholder="Qty"/></td></tr>
<tr><td width="200" >Cheese & Ham</td><td><input name="Cheese_Ham" type="text" style="width:50px;" placeholder="Qty"/></td></tr>
<tr><td width="200" >Fetta</td><td><input name="Fetta"type="text" style="width:50px;" placeholder="Qty"/></td></tr>
<tr><td width="200" >Goat & Cheese</td><td><input name="Goat_Cheese" type="text" style="width:50px;" placeholder="Qty"/></td></tr>
<tr><td width="200" >Halloumi</td><td><input name="Halloumi"type="text" style="width:50px;" placeholder="Qty"/></td></tr>
<tr><td width="200" >Labneh & Cucumber</td><td><input name="Labneh_Cucumber" type="text" style="width:50px;" placeholder="Qty"/></td></tr>
<tr><td width="200" >Pepper & Pate</td><td><input name="Pepper_Pate" type="text" style="width:50px;" placeholder="Qty"/></td></tr>
</table>
<div class="submit"><input type="submit" ID="submit" value="SUBMIT" ></div>
<input type="reset" value="RESET" ID="reset" >
并且列表继续包含200个名称。
我试图从我从互联网上收集的东西创建以下php表单:
<?php
if(isset($_POST['email'])) {
$email_to = "email@gmail.com";
$email_subject = "food";
foreach ($_POST as $Field=>$Value) {
if($Value != ''){
$body .= "$Field: $Value\n";
@mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
die();
?>
但事情似乎不起作用..
非常感谢你的帮助
答案 0 :(得分:1)
这应该有效。您没有关闭foreach循环或检查以查看该值是否包含数据。此外,您的邮件功能并未使用您在上面指定的$body
变量,并且其中包含额外的标头变量。
我还清理了一些代码以缩进它以提高可读性。
** note **你可以添加$ header来将消息格式化为HTML,或者如果你愿意,可以设置你的地址,但是如果它只是去找你,我就不会这么认为&#39必要的。
<?php
if(isset($_POST['email'])) {
$email_to = "email@gmail.com";
$email_subject = "food";
foreach ($_POST as $Field=>$Value) {
if($Value != ''){
$body .= "$Field: $Value\n";
}
}
mail($email_to, $email_subject, $body);
echo "Thank you for contacting us. We will be in touch with you very soon.";
}
?>
答案 1 :(得分:0)
立即尝试
<?php
if(isset($_POST['email'])) {
$email_to = "email@gmail.com";
$email_subject = "food";
foreach ($_POST as $Field=>$Value) {
if($Value != ''){
$body .= "$Field: $Value\n";
@mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
}
}
?>
大括号不匹配
答案 2 :(得分:0)
<?php
if(isset($_POST['email'])) {
$email_to = "email@gmail.com";
$email_subject = "food";
foreach ($_POST as $Field=>$Value) {
if($Value != ''){
$body .= "$Field: $Value" . "<br>";
}
}
@mail($email_to, $email_subject, $email_message, $headers);
}
?>
Thank you for contacting us. We will be in touch with you very soon.