PHPでHTMLメールを送信しようとしましたが、何も機能していません。私は2つの選択肢を試した。 file_get_contents
とPHPメーラーがhtmlメッセージを送信できません
ワン:
<?php
$to = '[email protected]';
$subject = 'Marriage Proposal';
$from = '[email protected]';
// 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";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = file_get_contents("email_template.html");
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>
そして、PHPの文字列のHTMLとの1:両方の機能のための
<?php
$to = '[email protected]';
$subject = 'Marriage Proposal';
$from = '[email protected]';
// 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";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Hi Jane!</h1>';
$message .= '<p style="color:#080;font-size:18px;">Will you marry me?</p>';
$message .= '</body></html>';
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>
応答は次のとおりです。
できませんが、電子メールを送信します。もう一度お試しください。電子メールを送信できません。 をもう一度お試しください。
誰も私に何が間違っていると言うことができますか?
を参照してくださいPHPのメーラーでHTMLを有効にしますか? – TFennis
すべてが正常に動作しています。私は今までプレーンテキストで合計10kメールを送信しました。しかし、HTMLを実装するとエラーが発生します。 普通のメールが配信されている場合、すべてがfine.idkのままであることを意味します。 – DrNawaf
タイトルを明確にするため、これは「PHPMailer」ではなく、phpでmail()関数を使用しています。大きな違い。 – mickmackusa