【问题标题】:HTML mail headersHTML 邮件标头
【发布时间】:2012-05-10 21:47:15
【问题描述】:

我在我的 Ubuntu 服务器上设置了 PHP 和 Postfix。我需要从 PHP 脚本发送 HTML 电子邮件。电子邮件发送得很好,但它显示为包含 HTML 标记的纯文本。此外,一些标题也显示在电子邮件本身中。

我的猜测是,它与标题有关。我花了将近一天的时间寻找可能的解决方案,但没有找到。

这是 PHP 代码:

$headers='';
$headers.="MIME-Version: 1.0 \r\n";
$headers.="Content-type: text/html; charset=\"UTF-8\" \r\n";
$headers.="From: ".FROM_EMAIL."\r\n";
mail($email, $vars['title'], $content, $headers);

编辑:

 $headers='';
 $headers.='MIME-Version: 1.0'."\r\n";
 $headers.='Content-type: text/html; charset=iso-8859-1'."\r\n";
 $headers.='From: Kinesioteip.ee<'.FROM_EMAIL.'>'."\r\n";
 $headers.='To: '.$email."\r\n";
 mail($email, $vars['title'], $content, $headers);

仍然没有运气......

【问题讨论】:

  • Dagon,它在浏览器中足够有效。
  • srini, $vars['title'] 是传递给发送电子邮件的函数的变量。目前我认为这并不重要。
  • 我刚刚使用了你编辑的标题,它们对我来说工作得很好,你为什么不向我们展示完整的 mail.php 代码,可能是其他一些导致问题的问题。
  • 我最近遇到了同样的问题。类似的代码工作正常,然后突然停止。在 Ubuntu 11.10 PHP5.3.6-13ubuntu3.6 上它失败了,但是在带有 PHP 5.3.10-1ubuntu3 的 Ubuntu 12.04 上它工作得很好。我猜 Ubuntu 11.10 在 PHP 中处理邮件的方式出了点问题。
  • m-t,请您给我那封电子邮件的来源。我知道服务器添加了一些默认的标头,可能与此有关。

标签: php html email ubuntu header


【解决方案1】:
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Additional headers
    $headers .= 'To:' . "\r\n";
    $headers .= 'From: Admin<youremail@email.com>' . "\r\n";
    // Mail it
    mail($to, $subject, $message, $headers);

【讨论】:

  • 请再看一遍第一篇文章。我更改了标题,但没有运气。
【解决方案2】:

你可以尝试改变这些行吗

$headers.="MIME-Version: 1.0 \r\n";
$headers.="Content-type: text/html; charset=\"UTF-8\" \r\n";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

看看有没有效果

【讨论】:

    【解决方案3】:

    我认为你的第四个标题是错误的,因为 FROM_EMAIL 变量没有'$'

    试试

            $headers.="From: ".$FROM_EMAIL."\r\n";
    

    $vars['title'] 变成 $var

     mail($email, $vars, $content, $headers);
    

    【讨论】:

    • 老兄,FROM_EMAIL 是一个常量,不需要美元符号。我知道我传递给函数的变量是正确的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    • 2016-09-13
    • 1970-01-01
    • 2011-08-26
    相关资源
    最近更新 更多