PHP + postfix: all emails copied to mailer-daemon -
i have ubuntu 12.10 box latest repository (apt-get) postfix. when send emails sendmail command line:
sendmail -r from@example.com -f from@example.com -t to@example.com the email sent to@example.com (and good).
however, when use php , function:
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 // $param = "-r " . $frommail . " -f " . $frommail . " \r\n"; mail($to, $subject, $message, $headers, $param); } then to@example.com and mailer-daemon (which set root in aliases) receives email.
the mailer-daemon email when read mailutils mail command is:
return-path: <from@example.com> delivered-to: mailer-daemon@localhost received: localhost (postfix, 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) followed base64 email. how can prevent mailer-daemon receive copy when sending email php?
not sure should delete question or let future help. found reason. in parameters, should use
$param = "-f" . $frommail; and without ."\r\n" instead of wrong:
$param = "-r " . $frommail . " \r\n";
Comments
Post a Comment