无法修改标头信息

时间:2012-05-10 07:56:33

标签: php

我收到了“警告:无法修改标头信息 - 已经发送的标头(在第147行的/process_contact.php中已经开始输出)”,而在php中使用mail()发送邮件给多用户。
    

    $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');
}

3 个答案:

答案 0 :(得分:5)

您已经echo编辑了某些内容后,您无法发送标题信息。有关如何解决此问题的信息,请参阅PHP output buffering

删除它,它应该工作:

echo "Mail Sent.";

答案 1 :(得分: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计为输出。

答案 2 :(得分:1)

在header()调用之前有一个echo语句,这将导致发送标头。您不能在标题()

之前输出任何内容