【问题标题】:Styling variable in php for email content [duplicate]php中用于电子邮件内容的样式变量[重复]
【发布时间】:2017-12-27 18:03:02
【问题描述】:

我目前有一个表单,可以在创建产品时发送一封电子邮件,其中包含表单中的一些内容。我遇到的麻烦是让电子邮件内容看起来正确,因为我无法弄清楚字符串的样式。目前我有这个设置..

$to = "email@email.com";
$subject = $id . " has been added to PMS";
$txt = "<h1>A Product has been added to PMS!</h1> \n<b>Details</b> \nPart Number: " . $id . "\nName: " . $name . "\nProduct Family: " . $family . "\nPRF: " . $PRF;
$headers = "From: email@email.com" . "\r\n" .
"CC: other@email.com";

mail($to,$subject,$txt,$headers);

我想在第一部分添加&lt;h1&gt;,但它只是简单地输出"&lt;h1&gt;A Product has been added to PMS!&lt;/h1&gt;" 我还想添加表格等,但如果不添加标签,我无法弄清楚如何将它们放入反而。

【问题讨论】:

  • 您正在发送纯文本电子邮件。如果要发送 HTML 电子邮件,则必须发送 HTML 电子邮件。我强烈建议为此使用 SwiftMailer 之类的库。

标签: php html css


【解决方案1】:

您需要在标题中提供内容类型。

  // To send HTML mail, the Content-type header must be set
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'From: email@email.com';
$headers[] = 'Cc: other@email.com';

欲了解更多信息,请查看此链接http://php.net/manual/en/function.mail.php

【讨论】:

    猜你喜欢
    • 2012-10-20
    • 2016-07-02
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    相关资源
    最近更新 更多