5

私はたくさん検索しましたが、これに対する解決策を見つけることができませんでした。コードを何時間も変更した後、php.net の例を試してみましたが、同じように動作します。

Gmailアドレスに送信するとすべて問題なく表示されますが、別のサーバーに送信するとhtmlとしてレンダリングされません。私は約8台のサーバーを試しましたが、4台がこの問題に苦しんでいます

これはコードです(phpの例):

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

これは gmail の「オリジナルを表示」です (gmail はクライアントのみで、メールは php サーバーから送信されます)、メッセージが正しく表示されません - html はそのままです:

Delivered-To: XXX
Received: by 10.220.35.74 with SMTP id o10csp285028vcd;
        Sun, 9 Dec 2012 03:18:35 -0800 (PST)
Received: by 10.220.238.139 with SMTP id ks11mr6865773vcb.49.1355051914996;
        Sun, 09 Dec 2012 03:18:34 -0800 (PST)
Received-SPF: softfail (google.com: best guess record for domain of transitioning             unknown does not designate 82.80.232.249 as permitted sender) client-ip=82.80.232.249;
Received: by 10.230.67.134 with POP3 id r6mf4415353vbi.4;
            Sun, 09 Dec 2012 03:18:34 -0800 (PST)
X-Gmail-Fetch-Info: gideon@example.com 5 mail.example.com 110 gideon@example.com
Received: from [82.80.232.249] by mail.example.com (ArGoSoft Mail Server .NET v.1.0.8.4)         with ESMTP (EHLO web9.wishosting.net)
    for <gideon@example.com>; Sun, 09 Dec 2012 13:18:02 +0200
Received: by web9.wishosting.net (Postfix, from userid 1168)
    id C82D03EE2EC; Sun,  9 Dec 2012 13:18:23 +0200 (IST)
        To: gideon@example.com, wez@example.com
Subject: Birthday Reminders for August
    X-PHP-Script: example.com/lp/mailtest.php for 89.139.28.204
MIME-Version: 1.0
Date: Sun, 09 Dec 2012 13:18:02 +0200
Message-ID: <x0otq4xc1dcboohp09122012011802@EAWEB1>
SPF-Received: none
X-FromIP: 82.80.232.249
From: gideon@example.com

Content-type: text/html; charset=iso-8859-1

To: Mary <mary@example.com>, Kelly <kelly@example.com>

From: Birthday Reminder <birthday@example.com>

Cc: birthdayarchive@example.com

Message-Id: <20121209111823.C82D03EE2EC@web9.wishosting.net>
Date: Sun,  9 Dec 2012 13:18:23 +0200 (IST)



    <html>
    <head>
      <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
              <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
            </tr>
    <tr>
          <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
      </table>
</body>
</html>
4

3 に答える 3

4

イヴァンのコメントは正しいです!

phpmailer lib を使用する以下の例を試してください。

<?php
//phpmailer lib
require_once 'class.phpmailer.php';

$mail = new PHPMailer(true); 

try {
    $mail->AddAddress('mary@example.com', 'Mary');
    $mail->AddAddress('kelly@example.com', 'Kelly');
    $mail->SetFrom('birthday@example.com', 'Birthday Reminder');
    $mail->AddReplyTo('no-reply@example.com', 'No-reply');
    $mail->Subject = 'Birthday Reminders for August';
    $mail->AltBody = 'Here are the birthdays upcoming in August!\nPerson:Joe BirthDay:3rd Aug 1970\nPerson:Sally BirthDay:17th Aug 1973\n'; 
    $mail->MsgHTML('
        <p>Here are the birthdays upcoming in August!</p>
        <table>
            <tr>
              <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
            </tr>
            <tr>
              <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
            </tr>
            <tr>
              <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
            </tr>
        </table>'
    );

    $mail->Send();

    echo "Message Sent OK<p></p>\n";
} catch (phpmailerException $e) {
    echo $e->errorMessage(); 
} catch (Exception $e) {
    echo $e->getMessage(); 
}
?>

PHPMailer はhttps://code.google.com/a/apache-extras.org/p/phpmailer/downloads/listからダウンロードできます。

https://code.google.com/a/apache-extras.org/p/phpmailer/wiki/ExamplesPageにあるサンプル

于 2012-12-09T12:35:34.230 に答える
2

これは、メッセージを表示する電子メールリーダーによって異なります。

Gmailおよび最新の電子メールクライアント(MS Outlook、Thunderbird、Evolutionなど)は、htmlコンテンツがある場合はhtmlをレンダリングしますが、一部の古い読者はhtmlをレンダリングできないため(リスや大群など)、プレーンテキストとしてレンダリングします。 )。

電子メールを任意のリーダーで適切にレンダリングするには、プレーンテキストとHTMLバージョンの両方の電子メールを電子メールの本文に挿入する必要があります。

それを行う最良の方法は、phpの電子メールにPHPmailer、SwiftMail、およびその他のラッパーを使用することですが、本当にそれを自分で行いたい場合は、これを試してください

また、一部の読者は、divやcssルールなどのさまざまなhtml要素の表示に問題があることに注意してください。MSOutlookがレンダリングできるタグとcssを使用することをお勧めします。

于 2012-12-09T12:12:50.887 に答える
0

MIME 境界を設定してみてください

// generate a random string to be used as the boundary marker
       $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

       // now we'll build the message headers
       $headers = "From: $from\r\n" .
       "MIME-Version: 1.0\r\n" .
          "Content-Type: multipart/mixed;\r\n" .
          " boundary=\"{$mime_boundary}\"";

       // here, we'll start the message body.
       // this is the text that will be displayed
       // in the e-mail
       $message="This is an example";

       // next, we'll build the invisible portion of the message body
       // note that we insert two dashes in front of the MIME boundary 
       // when we use it
       $message = "This is a multi-part message in MIME format.\n\n" .
          "--{$mime_boundary}\n" .
          "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
          "Content-Transfer-Encoding: 7bit\n\n" .
       $message . "\n\n";
于 2012-12-09T12:26:14.403 に答える