了解 sendmail 配置

发布于 2024-11-19 08:58:32 字数 2733 浏览 2 评论 0原文

我正在尝试让 php 在 Ubuntu linux 机器上通过“mail() 命令发送邮件。邮件似乎正在发送,然后被发送邮件丢弃 - 我不知道该怎么办 php mail() 函数返回 true 。

我已设置 evolutoin 在本地主机上通过 SMTP 发送邮件,并且已发送到

/var/log/mail。日志文件包含以下条目

Jul  9 15:15:34 anake postfix/pickup[1292]: 02879340040: uid=33 from=<www-data>
Jul  9 15:15:34 anake postfix/cleanup[2079]: 02879340040: message-id=<20110709141534.02879340040@anake>
Jul  9 15:15:34 anake postfix/qmgr[1293]: 02879340040: from=<[email protected]>, size=411, nrcpt=1 (queue active)
Jul  9 15:15:36 anake postfix/smtp[2082]: 02879340040: to=<[email protected]>, relay=smtp.ntlworld.com[81.103.221.11]:25, delay=2.3, delays=0.1/0.02/2.1/0.13, dsn=5.0.0, status=bounced (host smtp.ntlworld.com[81.103.221.11] $
Jul  9 15:15:36 anake postfix/cleanup[2079]: 5370B340042: message-id=<20110709141536.5370B340042@anake>
Jul  9 15:15:36 anake postfix/bounce[2083]: 02879340040: sender non-delivery notification: 5370B340042
Jul  9 15:15:36 anake postfix/qmgr[1293]: 5370B340042: from=<>, size=2228, nrcpt=1 (queue active)
Jul  9 15:15:36 anake postfix/qmgr[1293]: 02879340040: removed
Jul  9 15:15:36 anake postfix/local[2084]: 5370B340042: to=<[email protected]>, relay=local, delay=0.03, delays=0/0.02/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Jul  9 15:15:36 anake postfix/qmgr[1293]: 5370B340042: removed

。不明白它从哪里获取“发件人”地址。实际执行的代码是这样的:-

<?php 
    $to      = '[email protected]';
    $subject = 'Test email';  
    $message = 'hello - this has gone round the loop';
    $headers = 'From: [email protected]' . "\n" .
              'Reply-To: [email protected]' . "\n" .
              'X-Mailer: PHP/'. phpversion()."\r\n";
    if (mail($to, $subject, $message, $headers)) {
        echo "Message sent OK";
    } else {
        echo "message send failed";
    }

?>

任何人都可以发现问题出在哪里,我可以采取什么措施? 伊恩

I am trying to get php to send mail via the "mail() command, on a Ubuntu linux box. The mail appears to be going and then getting dropped by send mail - and I am at a loss as to what to do about it.

The php mail() function returns true. The mail is not delivered. I have set up evolutoin to deliver vi SMTP on localhost, and sent an email to the same user - and it is delivered.

The /var/log/mail.log file contains the following entries.

Jul  9 15:15:34 anake postfix/pickup[1292]: 02879340040: uid=33 from=<www-data>
Jul  9 15:15:34 anake postfix/cleanup[2079]: 02879340040: message-id=<20110709141534.02879340040@anake>
Jul  9 15:15:34 anake postfix/qmgr[1293]: 02879340040: from=<[email protected]>, size=411, nrcpt=1 (queue active)
Jul  9 15:15:36 anake postfix/smtp[2082]: 02879340040: to=<[email protected]>, relay=smtp.ntlworld.com[81.103.221.11]:25, delay=2.3, delays=0.1/0.02/2.1/0.13, dsn=5.0.0, status=bounced (host smtp.ntlworld.com[81.103.221.11] $
Jul  9 15:15:36 anake postfix/cleanup[2079]: 5370B340042: message-id=<20110709141536.5370B340042@anake>
Jul  9 15:15:36 anake postfix/bounce[2083]: 02879340040: sender non-delivery notification: 5370B340042
Jul  9 15:15:36 anake postfix/qmgr[1293]: 5370B340042: from=<>, size=2228, nrcpt=1 (queue active)
Jul  9 15:15:36 anake postfix/qmgr[1293]: 02879340040: removed
Jul  9 15:15:36 anake postfix/local[2084]: 5370B340042: to=<[email protected]>, relay=local, delay=0.03, delays=0/0.02/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Jul  9 15:15:36 anake postfix/qmgr[1293]: 5370B340042: removed

I do not understadn where it gets the "from" address from. The actual code executed is this:-

<?php 
    $to      = '[email protected]';
    $subject = 'Test email';  
    $message = 'hello - this has gone round the loop';
    $headers = 'From: [email protected]' . "\n" .
              'Reply-To: [email protected]' . "\n" .
              'X-Mailer: PHP/'. phpversion()."\r\n";
    if (mail($to, $subject, $message, $headers)) {
        echo "Message sent OK";
    } else {
        echo "message send failed";
    }

?>

Can anyone spot what is going wrong, and what I can do about it? Email addresses slightly munged in a rather obvious way.
Ian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷雾森÷林ヴ 2024-11-26 08:58:32

这里的“from”是信封发件人,即最终出现在 Return-Path 标头中的地址。该标头不能像其他标头一样进行更改,因为它实际上不是邮件的一部分,而是信封的一部分。 Return-Path 是退回邮件发送到的地址等。

您可以使用 mail() 函数的第五个参数更改信封发件人。 Postfix(您的服务器正在运行)、Sendmail 和 Exim 都可以使用 -f 标志更改信封发件人:

...
$extra_parameters = '[email protected]';
mail($to, $subject, $message, $headers, $extra_parameters);

The "from" here is the envelope sender, i.e., the address which will end up in the Return-Path header. This header cannot be changed in the same way as other headers since this is not actually part of the mail but part of the envelope. Return-Path is the address which bounces is sent to, among other things.

You may be able to change the envelope sender by using the fifth argument of the mail() function. Postfix (which your server is running), Sendmail and Exim all makes it possible to change the envelope sender using the -f flag:

...
$extra_parameters = '[email protected]';
mail($to, $subject, $message, $headers, $extra_parameters);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文