简体   繁体   English

使用php提交所有填充字段

[英]Submitting All Filled Fields using php

Hi I would like first to state that i am more of a designer than a developer. 嗨,我首先要说的是,我是一名设计师,而不是一名开发商。

i am creating a food list for a restaurant containing 200 different food types. 我正在为包含200种不同食物类型的餐厅创建食物清单。

below the HTML: 在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" >

and the list continues to contain the 200 names. 并且列表继续包含200个名称。

i Tried to create the following php form from stuff i collected from the internet: 我试图从我从互联网上收集到的东西创建以下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();
 ?>

But things doesn't seem to work.. 但是事情似乎不起作用。

Thank you a lot for the help 非常感谢您的帮助

This should work. 这应该工作。 You didn't close out your foreach loop or your check to see if the value has data. 您没有关闭foreach循环或检查该值是否包含数据。 Also, your mail function wasn't using the $body variable that you had assigned above and had an extra headers variable in it. 另外,您的邮件功能没有使用上面分配的$body变量,并且其中没有多余的headers变量。

I also cleaned up the code a little to indent it for better readability. 我还清理了一些代码以使其缩进以提高可读性。

** note ** You can add $headers to format the message as HTML or set your from address if you wanted, but if it's just going to you, I don't think it's necessary. **注意**您可以添加$ 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.";
}
?>

try this now 立即尝试

<?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
 }
 }
 }

 ?>

The braces were not matching 大括号不匹配

<?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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM