我是 PHP 新手,花了 10 个小时试图解决这个问题。
目标是获取输入此订单表格的所有数据,并通过 PHP 将其发送到我的电子邮件。
我有两个问题:
1.我可以让 PHP 从单个菜单项(例如:Mexican Tortas)发送数据,但是如何让 PHP 从多个菜单项(例如:Mexican Tortas、Fish Sandwich 和 Hamburger)发送数据?
2.如何告诉 PHP 不要从没有“多少”的菜单项发送数据?或“定制它?” 文本字段填写?
如果您能提供一个超级简单的示例(或学习资源的链接),我将不胜感激。
谢谢你,亚比雅
PHP
<?php
if(isset($_POST['submit'])) {
$to = "test@mywebsite.com";
$subject = "New Order";
$name_field = $_POST['name'];
$phone_field = $_POST['phone'];
$item = $_POST['item'];
$quantity = $_POST['quantity'];
$customize = $_POST['customize'];
}
$body = "Name: $name_field\nPhone: $phone_field\n\nItem: $item\nQuantity: $quantity\nCustomize: $customize";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
?>
HTML
<form action="neworder.php" method="POST">
<div class ="item">
<img style="float:left; margin-right:15px; border:1px Solid #000; width:200px; height:155px;" src="images/mexicantortas.jpg">
<h1>Mexican Torta - $8.50</h1>
<input name="item" type="hidden" value="Mexican Torta"/>
<h2>How Many? <font color="#999999">Ex: 1, 2, 3...?</font></h2>
<input name="quantity" type="text"/>
<h3>Customize It? <font color="#999999">Ex: No Lettuce, Extra Cheese...</font></h3>
<textarea name="customize"/></textarea>
</div><!-- ITEM_LEFT -->
<div class ="item">
<img style="float:left; margin-right:15px; border:1px Solid #000; width:200px; height:155px;" src="images/fishsandwich.jpg">
<h1>Fish Sandwich - $8.50</h1>
<input name="item" type="hidden" value="Fish Sandwich"/>
<h2>How Many? <font color="#999999">Ex: 1, 2, 3...?</font></h2>
<input name="quantity" type="text"/>
<h3>Customize It? <font color="#999999">Ex: No Lettuce, Extra Cheese...</font></h3>
<textarea name="customize"/></textarea>
</div><!-- ITEM_LEFT -->
<div class ="item">
<img style="float:left; margin-right:15px; border:1px Solid #000; width:200px; height:155px;" src="images/hamburgers.jpg">
<h1>Hamburger w/ Fries - $7.00</h1>
<input name="item" type="hidden" value="Fish Sandwich"/>
<h2>How Many? <font color="#999999">Ex: 1, 2, 3...?</font></h2>
<input name="quantity" type="text"/>
<h3>Customize It? <font color="#999999">Ex: No Lettuce, Extra Cheese...</font></h3>
<textarea name="customize"/></textarea>
</div><!-- ITEM_LEFT -->
<div class="horizontal_form">
<div class="form">
<h2>Place Your Order Now: <font size="3"><font color="#037B41">Fill in the form below, and we'll call you when your food is ready to be picked up...</font></font></h2>
<p class="name">
<input type="text" name="name" id="name" style="text-align:center;" onClick="this.value='';" value="Enter your name"/>
</p>
<p class="phone">
<input type="text" name="phone" id="phone" style="text-align:center;" onClick="this.value='';" value="Enter your phone #"/>
</p>
<p class="submit">
<input type="submit" value="Place Order" name="submit"/>
</p>
</div><!-- FORM -->
</div><!-- HORIZONTAL_FORM -->
</form>