Exim 会覆盖“from”从 PHP 发送 MIME 电子邮件时的标头

发布于 2024-10-09 01:30:54 字数 1494 浏览 8 评论 0原文

我正在使用 PHP Pear Mail_Mime 库发送电子邮件。在我的脚本中,我在发送消息之前设置了“From:”标头。这一切在运行 Mac OS X 的服务器上运行良好(可能使用 sendmail 作为邮件程序,尽管我不是 100% 确定)。发送测试电子邮件时,“发件人:”字段显示正确的发件人。

但是,如果我在使用 Exim4 作为邮件程序的 Linux 服务器上运行相同的脚本,电子邮件仍会发送,但“发件人:”标头显示为默认标头,而不是我在脚本中指定的标头。

我尝试在PHP的邮件功能的“附加参数”中设置“-f [来自电子邮件地址]”选项,但这似乎没有效果。

谁能告诉我如何让 from 标头与 Exim 正常工作?

非常感谢任何建议。

干杯, 汤姆

编辑:这是代码,以防有人有兴趣查看它。


<?php

  include_once('Mail.php');
  include_once('Mail/mime.php');


  $subject = "mime mail test";
  $from = "[email protected]";
  $to = "[email protected]";
  $visitor_email = $from;

  $message = new Mail_mime();
  $message->setTXTBody("hallo there!");


  $body = $message->get();
  $extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email);
  $headers = $message->headers($extraheaders);

  $mail = Mail::factory("mail");
  $result = $mail->send($to, $headers, $body, "", "-f [email protected] -r [email protected]");

  print_r($result);

?>



I'm using the PHP Pear Mail_Mime library to send email. In my script, I set the "From:" header before sending the message. This all works fine on a server running Mac OS X, (which presumably uses sendmail as the mailer, although I'm not 100% sure.) When sending a test email, the "From:" field shows the correct sender.

However, if I run the same script on a Linux server with Exim4 as the mailer, the email is still sent but the "From:" header shows up as a default instead of the one I specified in the script.

I've tried setting the "-f [from email address]" option in the "additional parameters" for PHP's mail function, but this seems to have no effect.

Can anyone tell me how I might get the from header to work properly with Exim?

Any advice is greatly appreciated.

Cheers,
Tom

EDIT: here's the code in case anyone is interested in looking at it.


<?php

  include_once('Mail.php');
  include_once('Mail/mime.php');


  $subject = "mime mail test";
  $from = "[email protected]";
  $to = "[email protected]";
  $visitor_email = $from;

  $message = new Mail_mime();
  $message->setTXTBody("hallo there!");


  $body = $message->get();
  $extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email);
  $headers = $message->headers($extraheaders);

  $mail = Mail::factory("mail");
  $result = $mail->send($to, $headers, $body, "", "-f [email protected] -r [email protected]");

  print_r($result);

?>



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

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

发布评论

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

评论(1

辞别 2024-10-16 01:30:54

您通过命令行发送(相对于 SMTP)。 Exim 仅允许受信任的发件人使用 -f 选项。要么:

  • 将其更改为使用 SMTP(这将允许您使用任何您想要的发件人,前提是您被允许发送电子邮件(这通常意味着基于 IP 或基于身份验证的控制)
  • 从受信任的用户(如 root)发送或 exim 用户)
  • 将发送邮件的用户添加到 exim 配置中的受信任用户列表中,如下所示:

    trusted_users = root:apache:www:exim:60001

You're sending via the command line (vs. SMTP). Exim only allows trusted senders to use the -f option. Either:

  • Change it to use SMTP (which will allow you to use whatever sender you want provided you are allowed to send email at all (which usually means IP-based or authentication-based controls)
  • Send from a user that is trusted (like root or the exim user)
  • Add the user sending the mail to the trusted user list in the exim config, which would look something like this:

    trusted_users = root:apache:www:exim:60001

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文