我最近构建了一个表单(见下文),我设法编写了一个php脚本,当我按下表单中的提交按钮时,我设置要发送的邮件.问题是在$ message变量的php脚本中,通过电子邮件发送的唯一内容是字符串,而不是$ name,$ customer_number等变量.
有人可以帮我指出错误吗?
表格:
<form name="bookingForm" method="post" action="send_dates.php">
<table border="0" cellspacing="1" cellpadding="2">
<tr>
<td>Booking From</td>
<td>:</td>
<td><input name="fromDate" id="fromDate" size="20"></td>
<td>To</td>
<td>:</td>
<td><input name="toDate" id="toDate" size="20"></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" id="name" size="30"></td>
</tr>
<tr>
<td width="20px">Telephone</td>
<td>:</td>
<td><input name="customer_telephone" id="customer_telephone" size="30"></td>
</tr>
<tr>
<td width="20px">Email</td>
<td>:</td>
<td><input name="customer_email" id="customer_email" size="30"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="submit" value="Submit" onClick="document.getElementById('ResetForm').click();">
<input type="reset" name="ResetForm" id="ResetForm" value="Reset"></td>
</tr>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)
PHP脚本send_data:
<?php
$name = $_POST["name"];
$fromDate = $_POST["fromDate"];
$toDate = $_POST["toDate"];
$email = $_POST["customer_email"];
$telephone = $_POST["customer_telephone"];
// Mail of recievers
$to = "ucjulian@gmail.com";
// Contact subject
$subject ="Reservation Enquiry from $name";
// Details
$message="
From: $name
Email: $customer_email
Telephone: $customer_telephone
--------------------------------------------------------------
Reservation date from: $fromDate to: $toDate ";
// Mail of sender
$mail_from="$customer_email";
$rev = mail($to,$subject,$message);
if($rev) {
echo 'booking request has been sent!';
}
else {
echo 'something has gone wrong. Please try again!';
} ?>
Run Code Online (Sandbox Code Playgroud)
您将变量定义为$email和$telephone,但分别将它们用作$customer_email和$customer_telephone.
更新任一区域中的名称用法,您应该进行设置.