使用PHP传递消息的HTML代码发送HTML电子邮件(send html email using p

2019-10-31 17:05发布

IAM发送HTML邮件中包含的表

当我在Gmail,Hotmail服务,雅虎帐户recive消息时,它工作正常,但其他客户端如微软的Outlook上接收时,它解决它的HTML代码!

这里是我的电子邮件标题

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

Answer 1:

我总是用这个功能,它可以帮助

  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);

        }


Answer 2:

我知道这是不是你的问题的答案,但我建议使用一个邮件库,这将让你更轻松地发送电子邮件,并支持诸如附件,认证等。
我建议SwiftMailer伟大的工程,是简单和有据可查的。



文章来源: send html email using php deliver message as html code