我正在运行安装了Directadmin和Exim的Centos 6.4服务器。 我们与Spamexperts.com一起使用传出过滤。 不知何故,当我用PHP发送电子邮件时,信封发送者正被重写为默认的Directadmin用户。 我找不到原因。
PHP脚本:
<?php $to = '[email protected]'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //mail($to, $subject, $message, $headers, "[email protected]"); mail($to, $subject, $message, $headers); ?>
当执行上面的PHP代码时,Exim会logging以下内容:
2014-03-19 10:32:29 1WQCrN-000511-4Z <= [email protected] U=userX P=local S=446 T="the subject" from <[email protected]> for [email protected] 2014-03-19 10:32:29 1WQCrN-000511-4Z ** [email protected] F=<[email protected]> R=spamexperts_smarthost_router T=spamexperts_smarthost_transport: SMTP error from remote mail server after MAIL FROM:<[email protected]> SIZE=1483: host smtp.antispamcloud.com [46.165.209.5]: 550-Verification failed for <[email protected]>\n550-Previous (cached) callout verification failure\n550 Invalid sender <[email protected]> 2014-03-19 10:32:29 1WQCrN-000516-I1 <= <> R=1WQCrN-000511-4Z U=mail P=local S=1544 T="Mail delivery failed: returning message to sender" from <> for [email protected] 2014-03-19 10:32:29 1WQCrN-000511-4Z Completed 2014-03-19 10:32:32 1WQCrN-000516-I1 => [email protected] F=<> R=spamexperts_smarthost_router T=spamexperts_smarthost_transport S=1586 H=smtp.antispamcloud.com [46.165.209.5] X=TLSv1:DHE-RSA-AES256-SHA:256 C="250 OK id=1WQCrW-00033I-Lu" 2014-03-19 10:32:32 1WQCrN-000516-I1 Completed
关键部分是粗体部分:
2014-03-19 10:32:29 1WQCrN-000511-4Z <= [email protected] U = userX P =本地S = 446 T =“主题” 来自<[email protected]> for me @ mydomain。 COM
当我将PHP脚本更改为:
<?php $to = '[email protected]'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers, "[email protected]"); //mail($to, $subject, $message, $headers); ?>
Exim日志显示如下:
2014-03-19 10:48:09 1WQD6X-000569-IR <= [email protected] U=userX P=local S=442 T="the subject" from <[email protected]> for [email protected] 2014-03-19 10:48:13 1WQD6X-000569-IR => [email protected] F=<[email protected]> R=spamexperts_smarthost_router T=spamexperts_smarthost_transport S=459 H=smtp.antispamcloud.com [198.7.58.154] X=TLSv1:DHE-RSA-AES256-SHA:256 C="250 OK id=1WQD6P-0002nu-00" 2014-03-19 10:48:13 1WQD6X-000569-IR Completed
看到关键部分没有被重写:
2014-03-19 10:48:09 1WQD6X-000569-IR <= [email protected] U = userX P =本地S = 442 T =“主题” 来自<[email protected]> for me @ mydomain。 COM
附加信息:
剥离exim.conf
[...] syslog_duplication = false local_from_check = false local_sender_retain = false untrusted_set_sender = * [...] # TRUSTED USERS # OPTIONAL MODIFICATIONS: # if you must add additional trusted users, do so here; continue the # colon-delimited list #trusted_users = mail:majordomo:apache:diradmin:${readfile{/etc/exim.users}} trusted_users = mail:majordomo:apache:diradmin:userX: trusted_groups = apache:userX ###################################################################### # REWRITE CONFIGURATION # ###################################################################### begin rewrite #* [email protected] F # There are no rewriting specifications in this default configuration file. ###################################################################### # ROUTERS CONFIGURATION # # Specifies how remote addresses are handled # ###################################################################### # ORDER DOES MATTER # # A remote address is passed to each in turn until it is accepted. # ###################################################################### # Spamexperts begin routers spamexperts_smarthost_router: driver = manualroute domains = ! +local_domains ignore_target_hosts = 127.0.0.0/8 condition = "${perl{check_limits}}" transport = spamexperts_smarthost_transport route_list = $domain smtp.antispamcloud.com::587 no_more # Remote addresses are those with a domain that does not match any item # in the "local_domains" setting above. # This router routes to remote hosts over SMTP using a DNS lookup. Any domain # that resolves to an IP address on the loopback interface (127.0.0.0/8) is # treated as if it had no DNS entry. #lookuphost: # driver = dnslookup # domains = ! +local_domains # ignore_target_hosts = 127.0.0.0/8 # condition = "${perl{check_limits}}" # transport = remote_smtp # no_more [...] # Spamexperts begin transports spamexperts_smarthost_transport: driver = smtp hosts_require_tls = smtp.antispamcloud.com # Spam Assassin spamcheck: driver = pipe batch_max = 100 command = /usr/sbin/exim -oMr spam-scanned -bS current_directory = "/tmp" group = mail home_directory = "/tmp" log_output message_prefix = message_suffix = return_fail_output no_return_path_add transport_filter = /usr/bin/spamc -u ${lookup{$domain}lsearch*{/etc/virtual/domainowners}{$value}} use_bsmtp user = mail # must use a privileged user to set $received_protocol on the way back in! [...]
*额外的笔记:
简短的回答:最好恕我直言,不要使用邮件(),而是添加一个很好的PHP邮件类,如PHPMailer到您的应用程序。
详细答案:
发送电子邮件时,您必须pipe理两个主要部分:
你的代码是设置头文件,这些头文件只包含项目#1中的内容。 您的代码的问题是,作为项目#2一部分的“信封发件人”没有被明确设置,所以Exim使用默认的$ USER @ $ HOSTNAME。 谷歌以“ 示例SMTP对话 ”来理解这些事情为什么和什么时候是重要的。
一般来说,当使用php mail()命令时,如何将信封设置设置为你想要的值是很困难和不明显的。 相反,使用一些具有更多可configuration性的东西,可以进行实际的SMTP连接(而不是直接调用/ usr / sbin / sendmail)。 是的,当SMTP服务器在本地主机上时,情况会更好,同样的原则也适用。 当您可以在信封中指定一个实际的SMTP连接(如PHPMailer类 )中的所有内容时,所有这些与您对抗的问题都将消失。
另外值得注意的是,下面的答案显示了如何使用ini_set()来解决mail()命令的问题,但我仍然更喜欢使用PHPMailer。