-1

我在 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! &nbsp;'.$_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');
}
4

3 回答 3

5

echo编辑完某些内容后,您将无法发送标头信息。有关如何解决此问题的信息,请参阅PHP 输出缓冲。

放下它,它应该可以工作:

echo "Mail Sent.";
于 2012-05-10T07:58:37.997 回答
2
echo "Mail Sent.";
header('Location: reservation.php?sentok');

那个^

无论如何,回显某些内容然后直接重定向是没有意义的。你可以改为Mail Sent输出reservation.php

if(isset($_GET['sentok'])) echo 'Mail Sent.';

编辑:

我认为您的错误消息指出了那里的语法错误:

$adminmessage="You have received an email from ".$_POST['email']. // <-- this
$to = "test1@gmail.com";

这会在我的本地设置中给我一个Undefined Variable通知,这反过来会阻止您调用header(),因为该通知被视为 php.ini 的输出。

于 2012-05-10T07:59:50.547 回答
1

您在 header() 调用之前有一个 echo 语句,这将导致发送标头。你不能在 header() 之前输出任何东西

于 2012-05-10T07:58:38.103 回答