[SOLVED] Sendmail to remote server for local domain ignores MX record

Problem: You have a contact us form hosted on your website sending an email to your local domain, but the email never leaves your web server because your mail server is hosted elsewhere. The mail works fine for all other email domains (your customers receive confirmation emails), but your own domain fails to arrive (cc'ing to yourself).

This is really mind boggling problem, and it took me a while to find a solution that works in my environment. In a nutshell, there are a number of solutions but in certain environment first few options doesn't work.

1. Change your hostname with 'hostname' linux command. To permanently change your server hostname, edit the /etc/sysconfig/network and change the hostname entry to something other than your mail domain. Restart network, i.e. "# service network restart".

2. Edit /etc/mail/sendmail.mc, and add the following two lines.

define(`MAIL_HUB', `example.com.')dnl
define(`LOCAL_RELAY', `example.com.')dnl

You are just faking your mail server to think that it's example.com. It has no negative impact on integrity of your email being treated as SPAM by the receiving mail server.

# cd /etc/mail
# make

You may have to install sendmail-cf module in order to create sendmail.cf from sendmail.mc file. (i.e. # yum install sendmail-cf)

Restart sendmail by running "service sendmail restart".

3. If all else fails, you may want to use 3rd party mail server to send an email from your PHP application. PHPmailer is a good SMTP mailer which you can use to send email via a 3rd party mail server.

**Note: If you have a shared hosting plan and have an access to cPanel or DirectAdmin, you may configure DNS to

If you're using version 11 and up, it automatically knows whether to use internal or external mail server based on the MX record configured within DNS zone. For older versions, click "MX Entry" icon in the Mail section. Choose the domain you wish to change, and choose "Remote Mail Exchanger" to indicate you're using external mail server.

cPanel makes use of the /etc/localdomains and /etc/remotedomains files to decide whether it should manage mail locally or do a DNS lookup and deliver mail externally.

Direct Admin:
1. Login to your control panel
2. Click "MX Record" under the E-Mail Management
3. Uncheck "Local Mail Server" and save.



Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.