简体   繁体   English

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

[英]Exim overwrites “from” header when sending MIME email from PHP

I'm using the PHP Pear Mail_Mime library to send email. 我正在使用PHP Pear Mail_Mime库发送电子邮件。 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. 在运行Mac OS X的服务器上,这一切都可以正常运行(尽管我不确定100%肯定使用sendmail作为邮件程序。)在发送测试电子邮件时,“发件人:”字段显示正确的发件人。

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. 但是,如果我在使用Exim4作为邮件程序的Linux服务器上运行相同的脚本,则仍会发送电子邮件,但默认情况下会显示“发件人:”标头,而不是我在脚本中指定的标头。

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. 我尝试为PHP的邮件功能在“其他参数”中设置“ -f [来自电子邮件地址]”选项,但这似乎没有效果。

Can anyone tell me how I might get the from header to work properly with Exim? 谁能告诉我如何从from标头中正常使用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 = "wtf@domain.com";
  $to = "wtf@domain.com";
  $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 wtf@domain.com -r wtf@domain.com");

  print_r($result);

?>


You're sending via the command line (vs. SMTP). 您是通过命令行(相对于SMTP)发送的。 Exim only allows trusted senders to use the -f option. Exim仅允许受信任的发件人使用-f选项。 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) 对其进行更改以使用SMTP(如果您完全可以发送电子邮件,则可以使用所需的任何发件人(通常意味着基于IP或基于身份验证的控件)
  • Send from a user that is trusted (like root or the exim user) 从受信任的用户(例如root或exim用户)发送
  • Add the user sending the mail to the trusted user list in the exim config, which would look something like this: 将发送邮件的用户添加到exim配置中的受信任用户列表,如下所示:

    trusted_users = root:apache:www:exim:60001 Trusted_Users = root:apache:www:exim:60001

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM