使用PHP发送格式化(粗体,html,...)电子邮件到Gmail

时间:2013-08-08 17:01:26

标签: php html email gmail

我发送一封带有PHP的电子邮件到gmail帐户。

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

我们如何格式化Gmail接收器看到预格式化的文本,如font-size / weight / etc ......?

1 个答案:

答案 0 :(得分:2)

您需要将消息的标题设置为HTML格式。在致电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";

尝试使用以下内容发送:

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