9

phpを使用して、このコードでプレーンテキストとして電子メールを受信しましたが、何かが足りませんでしたか?たとえば、リンクを含むフォーマットされた電子メールを送信する必要があるためです。

$to = "receiver@test.com";
$subject = "Password Recovery";

$body = '
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <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>
';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From: info@test.net\r\n"."X-Mailer: php";
if (mail($to, $subject, $body, $headers)) 
echo "Password recovery instructions been sent to your email<br>";
4

4 に答える 4

22

ヘッダーをリセットしました。

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From: info@test.net\r\n"."X-Mailer: php";

その最後の行にドットがありません。これは前の2つを上書きしています。

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: info@test.net\r\n"."X-Mailer: php";
于 2012-08-16T19:59:58.880 に答える
16

この例を見てください。これはphpでメールを送信するのに十分です。

<?php 
    //change this to your email. 
    $to = "abc@gmail.com";
    $from = "Example@example.com";
    $subject = "Hello! This is HTML email";

    //begin of HTML message 
    $message ="
<html> 
  <body> 
    <p style=\"text-align:center;height:100px;background-color:#abc;border:1px solid #456;border-radius:3px;padding:10px;\">
        <b>I am receiving HTML email</b>
        <br/><br/><br/><a style=\"text-decoration:none;color:#246;\" href=\"www.example.com\">example</a>
    </p>
    <br/><br/>Now you Can send HTML Email
  </body>
</html>";
   //end of message 
    $headers  = "From: $from\r\n"; 
    $headers .= "Content-type: text/html\r\n";

    //options to send to cc+bcc 
    //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]"; 
    //$headers .= "Bcc: [email]email@maaking.cXom[/email]"; 

    // now lets send the email. 
    mail($to, $subject, $message, $headers); 

    echo "Message has been sent....!"; 
?>
于 2012-08-16T20:00:09.690 に答える
2

特定のメールサーバーでも同じ問題が見つかりました。私の場合、解決策は、ヘッダーの行末として「\ r\n」ではなく「\n」を設定することでした。

于 2015-06-11T05:45:15.977 に答える
0

あなたの問題は$headersへの再割り当てが原因のようですが、私は同様の問題に遭遇し、原因が二重線で終わる「/ r/n」であることを発見しました。Bluemailなどの一部のメールアプリは、2行の末尾を読み取った後、メール本文を開始します(事実上ヘッダーを終了します)。

私の場合、これを変更することで解決しました。

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: info@test.net\r\n"."X-Mailer: php";

これに:

$headers  = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers = "From: info@test.net\n"."X-Mailer: php";
于 2020-04-18T19:31:07.677 に答える