send html email using php deliver message as html code

不羁的心 提交于 2020-01-06 07:46:56

问题


iam sending html message contains table

when i recive message on gmail,hotmail,yahoo account it works fine but when receiving on other client ie Microsoft outlook it resolve it as html code !!

here is my email headers

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

回答1:


I Always use this function ,and it helps

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

        }



回答2:


I know this isn't an answer for your question, but I suggest using a mailing library, that will allow you to send mails much more easily, and supports features such as attachments, authentication, etc.
I recommend SwiftMailer which works great, is simple and well documented.



来源:https://stackoverflow.com/questions/10616324/send-html-email-using-php-deliver-message-as-html-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!