)PHPを使用してかなり簡単なHTMLメールを送信しようとしています。私は最後の3日間、良い解決策を見つけようとしていましたが、私がそれを見つけたと思っていますが、私がそれをテストすると、正しく送信されません。私が参照していたチュートリアルの1つからこのコードを借りました。次のようにテストコードは次のとおりです。PHPメールでmultipart/alternativeを送信する(
<?php
//define the receiver of the email
$to = '[email protected]';
//define the subject of the email
$subject = 'Test HTML email';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: [email protected]\r\nReply-To: [email protected]";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello World!!!
This is simple text email message.
--<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>
--<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail($to, $subject, $message, $headers);
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
問題はそれだけで罰金、電子メールを送信しますが、それは、プレーンテキスト、またはGmailで空白のメッセージとして送信のどちらか、ということです。なぜどんなアイデア?
空のダウンロードファイルは、まさに私が得ていたものでした!私は別のチュートリアルを探して最初からやり直すことになりました。しかし、迅速な返信をありがとう! – Bryan
絶対に。図書館は不可欠です。自分のRFCに準拠した電子メールをPHPでまとめることは、私の最悪の敵に望むものではありません。あなたの電子メールが完全に準拠していない場合は、迷惑メールとして表示される可能性が非常に高いことがよくあります。それが間違っているリスクは単に高すぎます。 – tadman
私は '\ r \ n'を使用していた問題がありました.GmailはOutlookにメッセージを表示しませんでした。私はここで反対を行い、それを修正するためだけに '\ n'を使いました。奇妙なことに、どこでもCRLFを使うと言われていたからです。 – James