带有www-data的PHP邮件问题 [英] PHP mail issue with www-data

查看:100
本文介绍了带有www-data的PHP邮件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过以下代码通过PHP的mail函数调用sendmail:

I am trying to invoke sendmail via PHP's mail function by the following code:

$to      = 'blah@email.state.edu';
    $subject = 'test';
    $message = 'test';
    $headers = 'From: mail@smartrek.blah.me' . "\r\n" .
               'Reply-To: mail@smartrek.blah.me' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);

但是在我的mail.log中,我收到一条消息,发件人不是我在标头中指定的地址:

However in my mail.log I am getting a message that the from is not the address I specified in the header:

<www-data@Name>: Sender address rejected: Domain not found

这是为什么?我在ubuntu上运行PHP的fast-cgi 为什么sendmail不使用我通过PHP代码指定的标头?

Why is this?? I am running PHP's fast-cgi on ubuntu Why doesn't sendmail use the header that I have specified via the PHP code?

推荐答案

看起来www-data@Name是您的信封发件人"地址.信封的发件人"地址与电子邮件发件人:"标头中显示的地址有不同.这就是sendmail在与接收邮件服务器的"MAIL FROM/RCPT TO"交换中使用的原因.它被称为信封"地址的主要原因是出现在邮件标题和正文的外部之外,在邮件服务器之间的原始SMTP交换中.

It looks like www-data@Name is your envelope "from" address. The envelope "from" address is different from the address that appears in your "From:" header of the email. It is what sendmail uses in its "MAIL FROM/RCPT TO" exchange with the receiving mail server.The main reason it is called an "envelope" address is that appears outside of the message header and body, in the raw SMTP exchange between mail servers.

unix上的默认信封发件人"地址取决于您所使用的sendmail实现.但通常将其设置为正在运行的进程的用户名,后跟"@"和计算机的主机名.在典型的配置中,外观类似于username@example.com.

The default envelope "from" address on unix depends on what sendmail implementation you are using. But typically it will be set to the username of the running process followed by "@" and the hostname of the machine. In a typical configuration this will look something like username@example.com.

如果您的电子邮件被接收邮件服务器拒绝,或者需要更改退回电子邮件的发送地址,则可以更改信封发件人"地址来解决问题.

If your emails are being rejected by receiving mail servers, or if you need to change what address bounce emails are sent to, you can change the envelope "from" address to solve your problems.

要更改unix上的信封发件人"地址,请为sendmail二进制文件指定"-r"选项.您可以在php.ini中全局执行此操作,方法是在"sendmail_path"命令行中添加"-r"选项.您还可以通过在PHP中以编程方式通过将-r mail@smartrek.blah.me作为附加参数参数传递给mail()函数(第5个参数)来进行此操作.如果您在两个地方都指定了一个地址,则将使用两个"-r"选项来调用sendmail二进制文件,这些选项可能会具有不确定的行为,具体取决于您的sendmail实现.使用Postfix MTA,以后的"-r"选项将以静默方式覆盖以前的选项,从而可以设置全局默认值,并且在尝试在本地覆盖它时仍会表现出合理的行为.

To change the envelope "from" address on unix, you specify an "-r" option to your sendmail binary. You can do this globally in php.ini by adding the "-r" option to the "sendmail_path" command line. You can also do it programmatically from within PHP by passing -r mail@smartrek.blah.me as the additional parameter argument to the mail() function (the 5th argument). If you specify an address in both places, the sendmail binary will be called with two "-r" options, which may have undefined behavior depending on your sendmail implementation. With the Postfix MTA, later "-r" options silently override earlier options, making it possible to set a global default and still get sensible behavior when you try to override it locally.

关于可以传递给sendmail的可选标志: -f将设置发件人地址,-r将覆盖sendmail生成的默认返回路径(通常使用发件人地址) .如果您希望退回的地址与发件人地址不同,请尝试同时使用两个标志:-f mail@smartrek.blah.me -r bounced-mail@smartrek.blah.me

About optional flags that can be passed to sendmail: -f will set the From address, -r will override the default Return-path that sendmail generates (typically the From address gets used). If you want your bounce-backs to go to a different address than the from address, try using both flags at once: -f mail@smartrek.blah.me -r bounced-mail@smartrek.blah.me

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On

; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log =

这篇关于带有www-data的PHP邮件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆