使用 PHP 发送 HTML 电子邮件 将消息作为 HTML 代码传递


send html email using php deliver message as html code

>iam 发送 html 消息包含表

当我在Gmail,Hotmail,Yahoo帐户上接收消息时,它工作正常,但是在其他客户端上接收消息时即Microsoft展望它将其解析为 HTML 代码!

这是我的电子邮件标题

            'MIME-Version: 1.0' . "'r'n" .
    'Content-Type: text/html;charset= UTF-8' . "'r'n" .
            'From: me <me@client.com>'

我总是使用这个函数,它有帮助

  function sendHTMLemail($HTML,$from,$to,$subject,$fromname)
        {
            $headers = "From: ".$fromname." <".$from.">'r'n";
            $headers.= "Reply-To: ".$fromname." <".$from.">'r'n";
            $headers .= "MIME-Version: 1.0'r'n"; 
            $boundary = uniqid("HTMLEMAIL"); 
        // First we be nice and send a non-html version of our email        
            $headers .= "Content-Type: multipart/alternative;".
                        "boundary = $boundary'r'n'r'n"; 
            $headers .= "This is a MIME encoded message.'r'n'r'n"; 
            $headers .= "--$boundary'r'n".
                        "Content-Type: text/plain; charset=ISO-8859-1'r'n".
                        "Content-Transfer-Encoding: base64'r'n'r'n";                    
            $headers .= chunk_split(base64_encode(strip_tags($HTML))); 
            // Now we attach the HTML version
            $headers .= "--$boundary'r'n".
                        "Content-Type: text/html; charset=ISO-8859-1'r'n".
                        "Content-Transfer-Encoding: base64'r'n'r'n";                    
            $headers .= chunk_split(base64_encode($HTML)); 
            // And then send the email ....
            mail($to,$subject,"",$headers);
        }
我知道

这不是您问题的答案,但我建议使用邮件库,这将使您更轻松地发送邮件,并支持附件,身份验证等功能。
我推荐SwiftMailer,它工作得很好,简单且有据可查。