简体   繁体   English

Postfix / PHP Mail()以相同的电子邮件地址发送电子邮件,忽略标头$ from

[英]Postfix / PHP Mail() sends email as same email address, ignores header $from

We recently upgraded our webserver and one of the first issues we came across was having problems sending to the same domain because the website was hosted on a different server to the company's exchange server. 我们最近升级了Web服务器,遇到的第一个问题是由于网站托管在与公司交换服务器不同的服务器上,因此无法发送到同一域。 Anyway I fixed that it was some simple config changes and disabling the mail service for the domain. 无论如何,我修复了一些简单的配置更改并禁用了域的邮件服务。

Anyway, that's not working but what I didn't notice at the time when I was testing some PHP mail forms on the website was that they are all getting sent as my email address to the client. 无论如何,这是行不通的,但是当我在网站上测试某些PHP邮件表单时,我没有注意到的是,它们都是作为我的电子邮件地址发送给客户端的。

This is the PHP (Which I don't think is a problem) 这是PHP(我认为这不是问题)

<?php
    ini_set("sendmail_from", "noreply@******.com"); 

    $name       = $_POST['name'];
    $email      = $_POST['email'];
    $phone      = $_POST['phone'];
    $comments   = $_POST['comments'];
    $ip=$_SERVER['REMOTE_ADDR'];

    $recipient  = '*****@******.com';
    $subject    = "Comments submitted from the Contact Us form on www.wavesfm.com from $name" ;

    $message   = "This is an email submitted from the Contact Us form on the website www.*****.com containing details from $name \n";
    $message  .= "    \n";
    $message  .= "Name: $name \n";
    $message  .= "Email: $email \n";
    $message  .= "Phone Number: $phone \n";
    $message  .= "Comments: $comments \n\n\n";
    $message  .= "IP Address: $ip ";

    $headers   = "From: noreply@********.com \n";
    $headers  .= "Reply-To: $email";

    mail($recipient,$subject,$message,$headers);
    header( 'Location: http://www.*****.com/thanks.php' ) ; 
?>

Can anyone see any issues with that code? 谁能看到该代码的任何问题? I have tried adding -fnoreply@ * *.com as a send parameter but it wont change my own email address from appearing as the sender. 我尝试添加-fnoreply @ * * .com作为发送参数,但是它不会更改我自己的电子邮件地址,而不会显示为发件人。

I don't think this is a PHP issue it seems more like a Postfix issue, but whats really bothering me is how my email address which isn't used anywhere is appearing as the sender. 我认为这不是PHP问题,似乎更像是Postfix问题,但真正困扰我的是发件人似乎没有使用我的电子邮件地址。

Has anyone had experience with this before? 以前有没有人有经验? as before 2 weeks ago I hadn't used Postfix at all so its all rather new to me. 和2周前一样,我根本没有使用过Postfix,所以对我而言,这是相当新的。

Web Server: Cent OS, Plesk 11.0.9 Web服务器:Cent OS,Plesk 11.0.9

Mail Server: MS Exchange Mail Server / Using ORF 邮件服务器:MS Exchange邮件服务器/使用ORF

Postfix Log for one of the email's 一封电子邮件的Postfix日志

Mar 27 13:48:41 dedicated postfix/pickup[12199]: 652EFA106C5: uid=48 from= Mar 27 13:48:41 dedicated postfix/cleanup[14376]: 652EFA106C5: message-id=<20130327134841.652EFA106C5@dedicated.mydomain.com> Mar 27 13:48:41 dedicated postfix/qmgr[12198]: 652EFA106C5: from=, size=726, nrcpt=1 (queue active) Mar 27 13:48:41 dedicated postfix/smtp[14378]: certificate verification failed for mail.mydomain.com[82.888.888.51]:25: untrusted issuer /CN=clientdomain-WAV01-CA Mar 27 13:48:42 dedicated postfix/smtp[14378]: 652EFA106C5: to=, relay=mail.client_website.com[82.888.888.51]:25, delay=0.89, delays=0.04/0.01/0.36/0.48, dsn=2.6.0, status=sent (250 2.6.0 <20130327134841.652EFA106C5@dedicated.mydomain.com> [InternalId=11846] Queued mail for delivery) Mar 27 13:48:42 dedicated postfix/qmgr[12198]: 652EFA106C5: removed Mar 27 13:48:41专用postfix / pickup [12199]:652EFA106C5:uid = 48 from = Mar 27 13:48:41专用postfix / pickup [14376]:652EFA106C5:message-id = <20130327134841.652EFA106C5@dedicated.mydomain .com> 3月27日13:48:41专用postfix / qmgr [12198]:652EFA106C5:从=,大小= 726,nrcpt = 1(队列处于活动状态)3月27日13:48:41专用postfix / smtp [14378]:证书mail.mydomain.com [82.888.888.51]:25的验证失败:不可信的发行者/ CN = clientdomain-WAV01-CA 3月27日13:48:42专用的postfix / smtp [14378]:652EFA106C5:to =,relay = mail。 client_website.com [82.888.888.51]:25,延迟= 0.89,延迟= 0.04 / 0.01 / 0.36 / 0.48,dsn = 2.6.0,状态=已发送(250 2.6.0 <20130327134841.652EFA106C5@dedicated.mydomain.com> [ InternalId = 11846]已排队等待送达的邮件)3月27日13:48:42专用postfix / qmgr [12198]:652EFA106C5:已删除

There might be some string concatenation issues with the following code: 以下代码可能存在一些字符串连接问题:

$headers = "From: noreply@********.com \n";

try 尝试

$headers = "From: noreply@********.com \r\n";

I recommend using phpmailer class for sending emails which is widely used: https://github.com/Synchro/PHPMailer 我建议使用phpmailer类来发送被广泛使用的电子邮件: https : //github.com/Synchro/PHPMailer

The php.ini sendmail_from directive only really applies on windows boxes php.ini sendmail_from指令仅真正适用于Windows盒

sendmail_from string Which "From:" mail address should be used in mail sent from PHP under Windows. sendmail_from字符串在Windows下从PHP发送的邮件中应使用“发件人:”邮件地址。 This directive also sets the "Return-Path:" header. 该指令还设置“ Return-Path:”头。

I don't think it's a code issue as such. 我认为这不是代码问题。 Which user are you running the webserver+php environment from on your Linux box? 您从Linux机器上运行哪个用户来运行webserver + php环境? If you're running it as yourself then it's probably submitting to postfix using your email address. 如果您以自己的身份运行它,则可能是使用您的电子邮件地址提交给后缀。

Don't forget to tail /var/log/maillog if you're using postfix, that can tell you a lot and help you get to the bottom of the issue. 如果您使用的是后缀,别忘了在/ var / log / maillog后面加上尾号,这可以告诉您很多信息并帮助您深入了解问题的根源。

sudo tail -f /var/log/maillog

You could try signing up for a free account with Sendgrid and coupled with PHPMailer, Zend Mailer or Symfony Mailer libraries use that to send the emails and see if you get the same issue. 您可以尝试使用Sendgrid注册一个免费帐户,并与PHPMailer, Zend Mailer或Symfony Mailer库一起使用该帐户发送电子邮件,看看是否遇到相同的问题。

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

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