HTML电子邮件无法正确发送


HTML email wont send correctly

每次我尝试从PHP文件testsend.PHP发送电子邮件时,它都是纯文本电子邮件,而不是HTML电子邮件。。。

这是我的密码。

<?php
$to = "email@gmail.com";
$sub = "Rediku Verify";
$from = 'noreply@rediku.com';
// 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";
$headers = 'From: '.$from."'r'n".'X-Mailer: PHP/'.phpversion();
$message = '<html>';
$message .= '<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /></head>';
$message .= '<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">';
$message .= '<table width="100%" bgcolor="#ff5454" cellpadding="10" cellspacing="0"><tr valign="top" align="center"><td>';
$message .= '<table width="500" cellpadding="0" cellspacing="0" bgcolor="#ff6565">';
$message .= '<tr><td><img src="http://www.rediku.com/image/veriEm4.png" alt="Welcome To Rediku! Just verify your Account..." /></td></tr>';
$message .= '<tr><td style="padding:1em; font-family:Arial, Helvetica;"><h2 style="color:white; font-weight:200; letter-spacing:1px; font-size:1.15em; text-align:center;">Please click "Verify" below to continue to username selection...</h2></td></tr>';
$message .= '<tr><td style="padding:1em; font-family:Arial, Helvetica;"><a href="http://www.rediku.com/validate/vali.php">VALIDATE</a></td></tr>';
$message .= '</table></td></tr></table>';
$message .= '</body></html>';
if(mail($to, $sub, $message, $headers)){
    echo 'Your mail has been sent successfully.';
} else{
    echo 'Unable to send email. Please try again.';
}
?>

有人能告诉我我做错了什么吗。。。此外,当你还在做的时候。我如何在电子邮件中发送表单,而不被电子邮件客户端归类为垃圾邮件发送者?

太烦人了。

此处为

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
$headers = 'From: '.$from."'r'n".'X-Mailer: PHP/'.phpversion();

您覆盖$headers。您忘记了将from行添加到$headers而不是替换其内容的点。

它需要看起来像这样:

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
$headers .= 'From: '.$from."'r'n".'X-Mailer: PHP/'.phpversion();

为了在发件人而不是电子邮件中显示姓名,请这样写发件人:

$from = 'Rediku <noreply@rediku.com>';

即将电子邮件地址放在尖括号中,并在其前面添加要显示的文本。