PHP + postfix:所有电子邮件都复制到mailer-daemon

时间:2013-05-15 11:04:50

标签: php postfix-mta

我有一个带有最新存储库(apt-get)后缀的ubuntu 12.10盒子。当我从sendmail命令行发送电子邮件时:

sendmail -r from@example.com -f from@example.com -t to@example.com

电子邮件只发送给to@example.com(这很好)。

但是,当我使用PHP和这个函数时:

function mymail($to, $subject, $message, $frommail = "from@example.com", $fromname = "From Me") {
  $subject = "=?utf-8?B?" . base64_encode($subject) . "?=";
  $from = $fromname . " <" . $frommail . ">";
  $headers = "From: " . $from . " \r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  $headers .= "Content-Transfer-Encoding: base64\r\n\r\n";
  $message = base64_encode($message);
  $param = "-r " . $frommail . " \r\n";
  // Optionally tried also 
  // $param = "-r " . $frommail . " -f " . $frommail . " \r\n";
  mail($to, $subject, $message, $headers, $param);
}

然后to@example.com AND MAILER-DAEMON(我在aliases设置为root)收到电子邮件。

mailutils mail命令读取的MAILER-DAEMON电子邮件是:

Return-Path: <from@example.com>
Delivered-To: MAILER-DAEMON@localhost
Received: by localhost (Postfix, from userid 33)
    id 5663254EB; Wed, 15 May 2013 16:57:52 +0700 (ICT)
To: to@example
Subject: Test
X-PHP-Originating-Script: 1000:mail_func.php
From: FromMe <from@example.com> 
MIME-Version: 1.0
Content-type: text/html; charset=UTF-8
Content-Transfer-Encoding: base64
Message-Id: <20130515095752.5663254EB@localhost>
Date: Wed, 15 May 2013 16:57:52 +0700 (ICT)

后跟base64电子邮件。 如何通过PHP发送电子邮件时阻止MAILER-DAEMON收到副本?

1 个答案:

答案 0 :(得分:0)

我不确定是否应删除此问题或将其留待将来提供帮助。我刚刚找到了原因。在额外的参数中,我应该使用

$param = "-f" . $frommail;

且没有."\r\n"而不是错误:

$param = "-r " . $frommail . " \r\n";