0

I have A VPS with multiple domains setup. Some of the domains have PHP sites that send email. It turns out that some email servers are rejecting those emails with error: "Sender address rejected: Domain not found".(This from logs in exim_mainlog on server).

The interesting thing is that the domain it is reporting to be using as the sender is not the one I set in php mail(), rather an internal server name.

So for example if my VPS master domain is mymasterdomain.com and I have multiple sites such as site1.com, site2.com, etc, then the php program that sends email will send the email with a from field set in the header to: webapp@site1.com but the mail will be rejected with 'Sender address rejected: Domain not found in site1cpanelaccount@com.mymasterdomain.com'.

com.mymasterdomain.com is how the hosting company identifies my VPS server internally, and obviously it does not resolve to anything.

SPF records are set properly to include the IP address of the site. I did a test by using php to snd the same email to two addresses. One is rejecting it, but the other at a gmail account is accepting it, which lets me look at the headers.

I can see the problem- the headers have:


Received: from cpanelSite1Account by com.mymasterdomain.com with local (Exim 4.91) (envelope-from ) id 1fWXCF-0006ED-Vv; Fri, 22 Jun 2018 09:37:56 -0500

To: someone@somewhere.com

Subject: NEW INQUERY RECEIVED

X-PHP-Script: www.site1.com/inquire_process.php for XXX.XXX.XXX.XXX

X-PHP-Originating-Script: 522:inquire_process.php

From: webapp@site1.com


The [From:] is correct, but the [Received: from] contains the VPS info which is giving me trouble.

How do I fix this? In php? in cpanel? in sendmail or exim settings? Any help would be appreciated - have been scratching my had a while now ...

1

This is what probably happens:

  1. The receiving MTA checks existence against envelope sender instead of From: header.
  2. The Sendmail called by PHP mail() function uses the account@server.example.com as envelope sender, while the webapp@example.net in headers parameter of mail(to,subject,message,headers,parameters); is only used for generating mail headers.
  3. Sendmail gets its own hostname from the first host found for itself in /etc/hosts.

You could fix this on any level (the solutions in corresponding order, not the best first):

  1. Make the domain/hostname used as envelope sender exist by adding an A record.
  2. Use additional parameter to give Sendmail the envelope sender:

    mail('to@example.org','subject','message',
         'From: webapp@example.net',
         '-f webapp@example.net');
    

    From man sendmail:

    -f sender
    

    Set the envelope sender address. This is the address where delivery problems are sent to.

  3. Add an existing hostname in your /etc/hosts line for 127.0.0.1 or the actual server IP. This must be an A record from an existing domain, pointing at your server.

I think the solution #2 is nearest to your goal while #1 and #3 may solve the problem behind.

  • Option 2 did the trick! Thx. – foosy Jun 23 '18 at 18:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.