我想在后台发送两封电子邮件。它被空白页面困住了 这是代码
编辑后我想在后台发送两封电子邮件。它被空白页面困住了 这是代码
我想在后台发送两封电子邮件。它被空白页面困住了 这是代码
我想在后台发送两封电子邮件。它被空白页面困住了 这是代码
<?php
if (isset($_POST['send'])) {
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['email']) && preg_match('/^[0-9]*$/', $_POST['phnumber'])) {
//regular expression for email validation
$email = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phnumber'];
$adults = $_POST['adults'];
$children = $_POST['children'];
$package = $_SERVER['HTTP_REFERER'];
$to = "yathraatravels@gmail.com";
$subject = "Enquiry Request from Customer";
$subject1 = "Enquiry Request from Customer";
$message = '<table width="70%" cellspacing="0" cellpadding="5" border="1">
<tr>
<td colspan="2"><strong>Enquiry Request from Customer</strong></td>
</tr>
<tr>
<td width="15%"><strong>First Name:</strong></td>
<td width="85%">' . $name . '</td>
</tr>
<tr>
<td width="15%"><strong>Phone:</strong></td>
<td width="85%">' . $phone . '</td>
</tr>
<tr>
<td width="15%"><strong>Email:</strong></td>
<td width="85%">' . $email . '</td>
</tr>
<tr>
<td width="15%"><strong>No of Adults</strong></td>
<td width="85%">' . $adults . '</td>
</tr>
<tr>
<td width="15%"><strong>No of children</strong></td>
<td width="85%">' . $children . '</td>
</tr>
<tr>
<td width="15%"><strong>Package</strong></td>
<td width="85%">' . $package . '</td>
</tr>
</table>';
$message2 = "test email";
$from = $email;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <' . $from . '>' . "\r\n";
$headers1 = "MIME-Version: 1.0" . "\r\n";
$headers1 .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers1 .= 'From: <' . $from . '>' . "\r\n";
mail($from,$subject1,$message2,$headers1);
mail($to,$subject,$message,$headers);
}
}
if (!empty($_SERVER['HTTP_REFERER'])){
header("Location: ".$_SERVER['HTTP_REFERER']);}
else
{
header("Location: index.html");
}
?>
答案 0 :(得分:1)
你有一些缺少关闭括号。一个用于if (isset($_POST['send']))
条件语句,一个用于if (preg_match...)
条件语句。
另外,您没有与$message2
中的mail($email,$subject,$message2,$headers);
变量相关联的内容,因此已在下面添加。
如果直接访问PHP并显示错误消息,我还为else
和(isset($_POST['send']))
添加了一些if (preg_match("/^([a-zA-Z0-9])...
条件语句。
此外,您的preg_match
位置不正确,因此已重新定位。
我已经成功测试了以下内容:
<?php
if (isset($_POST['send'])) {
$email = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phnumber'];
$adults = $_POST['adults'];
$children = $_POST['children'];
$package = $_SERVER['HTTP_REFERER'];
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['email']) && preg_match('/^[0-9]*$/', $_POST['phnumber'])) {
//regular expression for email validation
$to = "yathraatravels@gmail.com";
$subject = "Enquiry Request from Customer";
$message = '<table width="70%" cellspacing="0" cellpadding="5" border="1">
<tr>
<td colspan="2"><strong>Enquiry Request from Customer</strong></td>
</tr>
<tr>
<td width="15%"><strong>First Name:</strong></td>
<td width="85%">' . $name . '</td>
</tr>
<tr>
<td width="15%"><strong>Phone:</strong></td>
<td width="85%">' . $phone . '</td>
</tr>
<tr>
<td width="15%"><strong>Email:</strong></td>
<td width="85%">' . $email . '</td>
</tr>
<tr>
<td width="15%"><strong>No of Adults</strong></td>
<td width="85%">' . $adults . '</td>
</tr>
<tr>
<td width="15%"><strong>No of children</strong></td>
<td width="85%">' . $children . '</td>
</tr>
<tr>
<td width="15%"><strong>Package</strong></td>
<td width="85%">' . $package . '</td>
</tr>
</table>';
$message2 = "test email"; // having it located here is IMPORTANT
$from = $email;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <' . $from . '>' . "\r\n";
mail($email,$subject,$message2,$headers);
mail($to,$subject,$message,$headers);
if (!empty($_SERVER['HTTP_REFERER'])){
header("Location: ".$_SERVER['HTTP_REFERER']);}
else
{
header("Location: index.html");
// echo "OK"; // used for my testing purpose
}
} // end brace for if (preg_match("/^([a-zA-Z0-9])...
else { echo "Sorry bad email."; exit ; }
} // closing brace for if (isset($_POST['send']))
else { echo "Sorry you cannot do this from here. Please fill in the form."; exit; }
?>