使用php将订单表单发送到邮件


Sending order form to mail with php

我选择了一个javascript订单表单(供人们指挥产品),并在我的网站上实现了它。我试图创建一个php文件,将表单内容发送到我的邮件地址,但我被卡住了,谷歌再也帮不了我了。。。为了测试,我只定义了php文件中的最后三个格式字段,Nom(=name)、Mobile和Subtotal。

整个源代码(javascript在html文件中,所以它很大)可以在这里找到:source

这只是表单代码,后面是"send_mail.php"文件中的代码:

    <form name="ordform" method="post" action="send_mail.php"" style="padding-top: 200px">
<table align="center" border="1" bgcolor="#800000"><tr>
<th width="192" BGCOLOR="YELLOW"><b>Produit</b></th>
<th width="72" BGCOLOR="YELLOW" align="center"><b>Qté</b></th>
<th width="120" BGCOLOR="YELLOW" align="center"><b>Prix par unité</b></th>
<th width="120" BGCOLOR="YELLOW" align="center"><b>Prix total</b></th>
</tr>
<script language="JavaScript"><!-- 
for (var rownum=1;rownum<=RowsInForm;rownum++) {
   document.write('<tr><td width=192 BGCOLOR="CYAN">')
   document.write('<select name="prodchosen'+rownum+'" onChange="updateRow('+rownum+')">')
   for (i=0; i<=ProductsInList; i++) {
      document.write ("<option>"+prodlist[i].name)
   }
   document.write ('</select></td>')
   document.write ('<td width=72 align="center" BGCOLOR="CYAN"><input class="num" name="qty'+rownum+'" value=""')
   document.write ('size=3 onChange="updateRow('+rownum+')"></td>')
   document.write ('<td width=120 align="center" BGCOLOR="CYAN">')
   document.write ('<input class="num" name="unitprice'+rownum+'" value="" ')
   document.write ('size=10 onfocus="this.blur()"></td>')
   document.write ('<td width=120 align="center" BGCOLOR="CYAN">')
   document.write ('<input class="num" name="extprice'+rownum+'" value="" ')
   document.write ('size=10 onfocus = "this.blur()"></td>')
   document.write ('</tr>')
}
//--></script>
<tr>
<label for="subtotal"><td width="384" colspan="3" align="right" BGCOLOR="YELLOW">Total:</td></label>
<td width="120" align="center" BGCOLOR="YELLOW"><input class="num" name="subtotal" id="subtotal" size="10" onfocus="this.blur()"></td></tr>
<tr>
<label for="Nom"><td width="384" colspan="3" align="right" BGCOLOR="YELLOW">Nom:</td></label>
<td width="120" align="center" BGCOLOR="YELLOW"><input type="text" name="Nom" id="Nom" size="10"></td></tr>
<tr>
<label for="Mobile"><td width="384" colspan="3" align="right" BGCOLOR="YELLOW">Mobile:</td></label>
<td width="120" align="center" BGCOLOR="YELLOW"><input type="text" name="Mobile" id="Mobile" size="10"></td></tr>
</table>
<center>
<input type="submit" name="submit" id="submit" value="Envoyer">
<input type="reset" value="Effacer"></center></form>
<?php
$to = "vanackerjeroen@hotmail.com";
$subject = "Kaz Order";
$Nom = $_REQUEST['Nom'];
$Mobile = $_REQUEST['Mobile'];
$subtotal = $_REQUEST['subtotal'];
$headers = "From: $Nom"; 
$fullmessage = " nom: {$Nom}'n tel: {$Mobile}'n subtotal: {$subtotal}";
$sent = mail($to, $subject, $fullmessage, $headers);
header('Location: index.html');
?>

在PHP中,您可以在send_mail.php文件中捕获这些(因为这是表单的操作)

在您的PHP文件顶部显示以下内容:

if(isset($_POST)){
    $nom = $_POST['nom'];
    .... any other variable.
    // send mail function using the above variables.
}

或者代替nom发布的任何其他变量。

我也会把底层php放在if中,因为你只想在有人发送了post请求的情况下使用它们。