简体   繁体   中英

mail() php doesn't send in html format

I tried questions already answered over here ( this , this , this , and others...), but nothing get worked... i have this function to send an email:

function send_email($para, $assunto, $msg){
    $to      = $para;
    $subject = $assunto;

    $message = '<html><body>';
    $message .= str_replace("\\r\\n","<br/>",$msg);
    $message .= '</body></html>';

    $headers = 'From: email@realemail.com' . "\r\n";
    $headers .= 'Reply-To: email@realemail.com' . "\r\n";
    $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";

    return mail($to, $subject, $message, $headers);
}

And i'm calling this with something like that:

$var = "<p><strong>...blablabla...</strong></p>";

send_email("email@email", "lalala", $var);

I can send the email, but it ins't html formatted (and it contains the html tags, except for HTML and BODY ). What am i doing wrong?

EDIT 1 : The email is displayed like this (exactly the same content sent, except for HTML and BODY TAG):

BEGIN
<p><strong>...blablabla</strong></p>
END

When i get the full email (like this tutorial), shows up that the email was sent with TAGS html, body, etc... A piece of the email:

Delivered-To: myemail@gmail.com
...
To: myemail@gmail.com
Subject: aaaaaaaaaaaaaaaaaaaaa
From: sender@email.com
Reply-To: sender@email.com
X-Mailer: PHP/5.6.19
Content-type: text/html; charset=iso-8859-1
MIME-Version: 1.0
...
Date: Tue, 29 Nov 2016 15:51:48 -0200
...
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - svr1.ravehost.com.br
X-AntiAbuse: Original Domain - gmail.com
X-AntiAbuse: Originator/Caller UID/GID - [99 497] / [47 12]
X-AntiAbuse: Sender Address Domain - svr1.ravehost.com.br

<html><body>...blablabla...</body></html>

Not sure if this is an exact solution, but this solved html email problems I was having with Microsoft Outlook.

Replace all of the \\r\\n in the headers with PHP_EOL . I did this when I was having issues with sending html emails in PHP, and it seemed to solve my particular problems.

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