使用PHP Mail()格式化HTML
我正在通过下面的php代码发送一封电子邮件,该代码将电子邮件模板发送到用户的电子邮件地址。但是,电子邮件发送时,所有HTML标记仍然可见且无效使用PHP Mail()格式化HTML,php,html,Php,Html,我正在通过下面的php代码发送一封电子邮件,该代码将电子邮件模板发送到用户的电子邮件地址。但是,电子邮件发送时,所有HTML标记仍然可见且无效 $fh = fopen('templates/customer.eml','r'); $emailContents = fread($fh, filesize('templates/customer.eml')); $emailContents = str_replace(":name:", $person->fi
$fh = fopen('templates/customer.eml','r');
$emailContents = fread($fh, filesize('templates/customer.eml'));
$emailContents = str_replace(":name:", $person->first . " " . $person->last, $emailContents);
$emailContents = str_replace(":meeting_name:", $meeting->name, $emailContents);
$emailContents = str_replace(":chair:", $chair->first . " " . $chair->last, $emailContents);
fclose($fh);
$header = "FROM: vra@vodafone.com\r\n";
$header = "MIME-Version: 1.0\r\n";
$header.="Content-type: text/html; charset: utf8\r\n";
mail($person->email , "Meeting Request", $emailContents, "FROM: user@domain.com");
下面是我用于内容的电子邮件模板文件:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<p>
Dear :name:,<br />
You have been invited to <em>:meeting_name:</em> chaired by :chair:.
</p>
<p>
Main text of the email will go here<sup>*</sup>.
</p>
<p>
Thankfully
</p>
<p>
User
</p>
</body>
</html>
亲爱的:姓名:,
您已被邀请参加:会议名称:主席:主席:。
电子邮件的主要文本将显示在此处*。
谢天谢地
使用者
您没有将标题传递到邮件函数中。尝试:
$header = "FROM: vra@vodafone.com\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .="Content-type: text/html; charset: utf8\r\n";
mail($person->email , "Meeting Request", $emailContents, $header);
试试这些标题
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=utf8' . "\r\n";
$header .= 'From: vra@vodafone.com' . "\r\n";
mail($person->email , "Meeting Request", $emailContents, $header);
对不起,我弄错了。我已将$header更新到邮件函数中。但是我现在没有收到电子邮件?谢谢你发布代码,它起作用了:)非常感谢你的帮助。感谢您没有读取$header变量。你只是附加物而已。