Php – Send formated (bold, html, …) Email to Gmail with PHP

emailgmailhtmlPHP

I am sending an e-mail with PHP to a gmail account.

$message = 
"Hi Mario

Today Luigi tried to <b>eat</b> <span style="font-size:8px">Toad</span>. 
I am so sorry that formating gmail is not standard. This mail will display the breaks made,
like in heredoc, but not the html. Help me understanding to format E-mails for 
Gmail-receivers.

It's a me
Greetings, 
Wario";

mail("mario@gmail.com", "Betreff: Luigi nibbled Toad",
$message, "From: itsame@myphpmail.com" );

How could we format that Gmail receivers see preformated text like font-size/weight/etc… ?

Best Answer

You need to set the headers of the message to be formatted in HTML. Add this before your call to mail().

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Itsame <itsame@myphpmail.com>' . "\r\n";

Than try sending it with the following:

mail("mario@gmail.com","Betreff: Luigi nibbled Toad", $message, $headers);