How do I Ignore local DNS and route email to internet

I have a dedicated server running Linux (CentOS)
I have two domains on the server and has the website hosted on the server but it uses a different server for its email.  So the MX record for points to another commercial server (demon internet) who handle the email then forward it to the customers exchange server.

However the second domain needs to send emails to but these do not arrive.  After some head scratching I have come to the conclusion that the dedicated server is checking to see if is local , deciding it is because the website is hosted on the server, it is then trying to deliver the email to the dedicated server.  This fails becasue the dedicated server isn't storing the email for

Is there a way I can tell the dedicated server that when it has email for from to send the mail on to the internet where it will then pick up the correct MX record and forward it to demons mail and onto the customer.
Who is Participating?
web server2 is sending mail to webserver1 instead of sending it to email server for domain1

webserver 2 should use an smtp relay outside of itself ideally. Or sendmail should be configured right. It doesnt seem to be trying to get the mx records for the domain.

you could try using XpertMailer script which allows you to send mail via smtp also.

Also found this at php mail() functions webpage if it relates:

You must take extra care if the machine that is sending the mail also operates mail forwarding for your domain and you are sending mail to a user at that domain.  In this situation, it is common for the MTA to avoid doing a "proper" MX look-up because it "knows" that there is a local list of mail-forwarding rules. This saves resources, and normally shouldnt be a problem, of course.

HOWEVER, if you deliberately alter your MX record to point to a mail server hosted elsewhere and, e.g. update your mail forwarding rules at that location,  AND the server that sends your PHP-generated mail "decides" that it will save resources by not checking the MX record THEN it will use your old set of forwarding rules because it is ignoring your MX record.
How does "domain" send emails Do you have a nameserver running on the server?

Nacho_ManAuthor Commented:
No the server does not run it's own nameserver, the hosting company has nameservers which we use.  
On-Demand: Securing Your Wi-Fi for Summer Travel

Traveling this summer?Check out our on-demand webinar to learn about the importance of Wi-Fi security and 3 easy measures you can start taking immediately to protect your private data while using public Wi-Fi. Follow us today to learn more!

Still: how is the mail from "domain" being sent to Is it a web php form, a remote user using a mail gateway, some local process ,..., etc.? There are a million ways of emitting mail from "domain" which seem to be sent to the wrong (namely example1 webserver) server.
Nacho_ManAuthor Commented:

The email is generated via php script using the "mail" command as an order confirmation.  One is sent to the customer and one to the people handling the orders. Both emails are generated and sent and customers get their copy without a problem.  

So I am assuming it is using sendmail.

Is that any help?
What's in the mail log (ususally under /var/log), just after you've unsuccessfully sent an email through the php form?
is there a mx record internally that is pointing to the web server for it seems to me if you can make sure the mx record in dns is set to outside internet host, the webserver in question will then route to right place.

what dns server is the web server with form using?

Nacho_ManAuthor Commented:
The final quote there pointed me in the right direction ... there is a etc\localdomains file on the server which if edited to remove domain with remote mail server and added to remotedomains file email for that domain is not rooted locally.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.