2

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 protected]' . "\r\n";
    $headers .= 'Reply-To: [email protected]' . "\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: [email protected]
...
To: [email protected]
Subject: aaaaaaaaaaaaaaaaaaaaa
From: [email protected]
Reply-To: [email protected]
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>
9
  • could you eventually also copy/paste here the resulting e-mail message with headers and all? Commented Nov 29, 2016 at 19:03
  • See the edit1 @Dragos. Commented Nov 29, 2016 at 21:35
  • Other then the headers being in incorrect order your code looks fine. Maybe there is a problem on the client side, which mail client are you using? Commented Nov 29, 2016 at 21:46
  • 2
    Try changing Content-type to Content-Type (upper case the T). Commented Nov 29, 2016 at 21:49
  • @PMateus E-mail, proper MIME encoding, and multi-part messages are an utter nightmare and you would be crazy to have to figure out all the quirks yourself. :-) Use an existing mail library that does this for you, such as PHPMailer or similar. Commented Nov 29, 2016 at 21:51

1 Answer 1

-2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

PHP_EOL changes its value depending on the platform you're using. If you run PHP on Windows, you'll get \r\n. If you run it on Linux, you'll get \n.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.