繁体   English   中英

使用PHP Mail()格式化HTML

[英]Formatting HTML using PHP Mail()

我正在通过下面的php代码发送电子邮件,该电子邮件将电子邮件模板发送到用户的电子邮件地址。 但是,电子邮件发送的所有HTML标记仍然可见并且无效。

$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>

您没有将标头传递给mail函数。 尝试:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM