-1

複数のユーザーにメールを送信するために PHP で mail() を使用しているときに、「警告: ヘッダー情報を変更できません - ヘッダーは既に送信されています (出力は process_contact.php:5 で開始されています) (/process_contact.php on line 147 )」。

    $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";

これにより、ローカルセットアップで通知が表示され、その通知がphpによる出力としてカウントされるため、Undefined Variable呼び出しが停止されます。header()

于 2012-05-10T07:59:50.547 に答える
1

header() 呼び出しの前に echo ステートメントがあり、ヘッダーが送信されます。header() の前に何も出力してはいけません

于 2012-05-10T07:58:38.103 に答える