简体   繁体   中英

send html email using php deliver message as html code

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>'

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

        }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM