2

For some reason my php mail() function does not send html,

Instead of <a href="mysite">link</a> it shows just shows link as plain text.

Any ideas?

this is the headers I used:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

// Additional headers
$headers .= 'From: My Automated Message <[email protected]>' . "\r\n";

And invoked as follows:

try {
    if (@mail($to_email, $subject, $message, $headers)){
        echo "<span style=\"color:#0D0; font:10pt Tahoma;font-weight:bold;\">{$SENT_MESSAGE}</span><br><br>"; 
        return true;
    } else {
        $tmp=error_get_last();
        throw new Exception($tmp['message']);
    }
} catch (Exception $e) {
    echo "<span style=\"color:red; font:10pt Tahoma;font-weight:bold;\">Error: ".$e->getMessage()."</span><br><br>";
}

I also tried to send the mail without headers, but then again it shows the link as plain text like this: <a href="mysite">link</a>

2 Answers 2

1

Try this header

  $headers = 'From: Name<[email protected]>' . "\r\n" .
       'Content-Type: text/html; charset=UTF-8' . "\r\n" .
       'MIME-Version: 1.0' . "\r\n" .
       'Content-Transfer-Encoding: base64' . "\r\n" .
       'X-Mailer: PHP/' . phpversion();
Sign up to request clarification or add additional context in comments.

7 Comments

Then try this one , hope this will help you $headers = 'From: Name<[email protected]>' . "\r\n" . 'Content-Type: text/html; charset=UTF-8' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
nope, it's still the same, the link word is just a plain text.
I tried on yandex.ru and mail.ru - both get me the same result.
are you kidding? These are largest providers in Russia. I also used to send and recieve the links just fine, when I send them mail using sockets.
try this toooo $message = rtrim(chunk_split(base64_encode($message))); $headers = 'From: Abuse Digest Notification<[email protected]>' . "\r\n" . 'Content-Type: text/html; charset=UTF-8' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
|
0

Check this

 $from='[email protected]';      
 $headers ='';
 $headers .= 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 $headers .= 'From: '.$from.' '. "\r\n";

 mail($to_email, $subject, $message, $headers);

Comments

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.