PHP mail issue with www-data

后端 未结 6 695
野趣味
野趣味 2020-12-08 10:34

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

$to      = \'blah@email.state.edu\';
    $subject = \'test\';
    $message = \         


        
相关标签:
6条回答
  • 2020-12-08 10:53

    This worked for me:

    $mail->Sendmail = $mail->Sendmail.' -f '.$mail_errorsto; 
    
    0 讨论(0)
  • 2020-12-08 10:58

    In my case, I've got a hosted server so I needed to edit this file :

    /etc/ssmtp/ssmtp.conf

    Then uncomment this line :

    FromLineOverride=YES

    Once done, personals headers are working.

    0 讨论(0)
  • 2020-12-08 11:06

    I was having similar problem with www-data when all my mails were sent and received with this header:

    From: www-data <www-data@example.com>
    

    I used the -f info@example.com flag as 5th argument with the PHP email() function (as mentioned in accepted answer), but i was still receiving my emails as:

    From: www-data <info@example.com>
    

    So i added one more flag -f info@example.com -F info to set the full name of the email and finally i was getting emails as i wanted:

    From: info <info@example.com>
    

    I'm posting this answer because nobody mentions it here and i got a little stuck on it.

    0 讨论(0)
  • 2020-12-08 11:07

    I had this issue using exim4 with smarthost. The mails were sent with

    Return-path: <www-data@servername>
    

    which was rejected by the ISP. I needed to change it to at least www-data@example.com (assuming 'example.com' is the servers public domain name). I could achieve that by changing /etc/mailname from

    servername
    

    to

    example.com
    

    This has already worked for me, having www-data@example.com as Return-path.

    However - If you want to completely change the email address, you can configure it in /etc/email-addresses as

    www-data: notifications@example.com
    

    After that the emails have been sent by default with

    Return-path: <notifications@example.com>
    
    0 讨论(0)
  • 2020-12-08 11:10

    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.

    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.

    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.

    EDIT

    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

    my php.ini

    [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 =
    
    0 讨论(0)
  • 2020-12-08 11:14

    Although this is an old question, I'm adding this answer in case it is of help to someone:

    I had the same problem with the From: header being re-written to www-data@host... I eventually tracked it down to the ssmtp bridge service that was piping mail from our web server into our mailserver. I added the line FromLineOverride=YES in the file /etc/ssmtp/ssmtp.conf and the problem disappeared.

    0 讨论(0)
提交回复
热议问题