[英]Submitting All Filled Fields using php
嗨,我首先要說的是,我是一名設計師,而不是一名開發商。
我正在為包含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();
?>
但是事情似乎不起作用。
非常感謝您的幫助
這應該工作。 您沒有關閉foreach循環或檢查該值是否包含數據。 另外,您的郵件功能沒有使用上面分配的$body
變量,並且其中沒有多余的headers變量。
我還清理了一些代碼以使其縮進以提高可讀性。
**注意**您可以添加$ header以將消息格式設置為HTML,也可以根據需要設置發件人的地址,但是,如果這只是給您的話,我認為沒有必要。
<?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.";
}
?>
立即嘗試
<?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
}
}
}
?>
大括號不匹配
<?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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.