【问题标题】:PHP Sendmail sender name is always Apache when header have attachment当标头有附件时,PHP Sendmail 发件人名称始终为 Apache
【发布时间】:2012-09-09 16:31:31
【问题描述】:

我们正在尝试使用 sendmail 发送电子邮件。正常的标头一切正常,但是当我们在标头中添加附件时,发件人名称为 Apache。这是我们的代码sn-p

$from_email = "noreply@domain.com";
$separator = md5(time());
$eol = PHP_EOL;
$filename = "attachment.pdf";
$attachment = chunk_split(base64_encode(file_get_contents($filename)));
$text = "Hi!";

// main header (multipart mandatory)
$headers  = "From:".$from_email.$eol;
$headers  = "Bcc:user@domain.com".$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$message .= "--".$separator.$eol;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$message .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$message .= $text.$eol.$eol;

// attachment
$message .= "--".$separator.$eol;
$message .= "Content-Type: application/pdf".$eol;
$message .= "Content-Transfer-Encoding: base64".$eol;
$message .= "Content-Disposition: attachment; filename=\"".$filename."\"".$eol;
$message .= $attachment.$eol;
$message .= "--".$separator."--".$eol;

$b = mail($email, "Your Issue of the STQ",$message, $headers, "-fnoreply@domain.com");

通过添加 -fnoreply@domain.com,我们在来自:noreply@domain.com (Apache) 的电子邮件标题中得到这样的结果。不确定这个 Apache 来自哪里?

这可能是什么问题。

谢谢

【问题讨论】:

    标签: php apache sendmail


    【解决方案1】:

    制作这样的标题:

    $headers .= 'From: <webmaster@example.com>' . "\r\n";
    

    也缺少 xyzz 指向的第二行上的点

    【讨论】:

      【解决方案2】:

      您需要在第二行添加一个点。

      $headers  = "From:".$from_email.$eol;
      $headers  .= "Bcc:user@domain.com".$eol;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-10
        • 1970-01-01
        • 2020-11-13
        • 2011-01-02
        • 2021-04-26
        • 2019-12-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多