我在 php 中使用 mail() 向多个用户发送邮件时收到“警告:无法修改标头信息 - 标头已发送(输出从 process_contact.php:5 开始)(第 147 行的 /process_contact.php)”。
$from = "test@gmail.com";
$adminmessage="You have received an email from ".$_POST['email'].
$to = "test1@gmail.com";
$subject = "Email Received for an Order";
$message = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body>
Online Reservation Form has been submitted on the website on '.$date.'.<br><br>
<table width="710px" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="40%" height="30" valign="top">Name:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["name"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Address:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["address"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Phone no.:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["phone"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">E-mail:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["email"].'</b></td>
</tr>
<tr>
<tr>
<td width="40%" height="30" valign="top">Check Out:</td>
<td width="60%" height="30" valign="top"><b>'. $_POST["price"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Night:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["night"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Rooms:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["rooms"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Adults:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["adults"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Children:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["children"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Room Type:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["roomtype"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Price:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["price"].'</b></td>
</tr>
<tr>
<p><strong>Payment Details</strong></p>
</tr>
<tr>
<td width="40%" height="30" valign="top">Payment Type:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["paymentype"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Card Name Holder:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["cardholder"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Credit Card no.:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["creditcardno"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Expiration Date:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["exp"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Security Code:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["securitycode"].'</b></td>
</tr>
<tr>
<p>Payment Details</strong></p>
</tr>
<tr>
<td width="40%" height="30" valign="top">Billing Address( Street adress ):</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["billing1"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Billing Address( City/State/Zip ):</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["billing2"].'</b></td>
</tr>
<tr>
<td width="40%" height="30" valign="top">Special Request:</td>
<td width="60%" height="30" valign="top"><b>'.$_POST["comments"].'</b></td>
</tr>
</table>
</body></html>';
$headers = "From:" . $from."\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
ini_set("SMTP","192.168.0.30");
$date = date("m/d/Y H:i:s");
mail($to,$subject,$message,$headers);
//for client
$from="test@gmail.com";
$to1=$_POST['email'];
$subject1="Confirmation";
$clentmessage1 ='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body><p>Dear Customer! '.$_POST["name"].'.Your reservation has been confirmed.<br>
Thank you for Emailing us. We will get back to you shortly.<br/>
Plz donot hesitate to contact us atfor further information or any queries!<br/><br/><br/>
<strong>Super Value Inn</strong>
</body>
</html>';
$headers = "From:" . $from."\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
ini_set("SMTP","192.168.0.30");
mail($to1,$subject1,$clentmessage1,$headers);
echo "Mail Sent.";
header('Location: reservation.php?sentok');
exit();
}
else
{
header('Location: reservation.php?err');
}