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 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 environments, the first few options don't work.

Solution:

1. Change your hostname with the '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 the 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 that you can use to send email via a 3rd party mail server.

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

cPanel

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

Share this post

Comments (0)

    No comment

Leave a comment

All comments are moderated. Spammy and bot submitted comments are deleted. Please submit the comments that are helpful to others, and we'll approve your comments. A comment that includes outbound link will only be approved if the content is relevant to the topic, and has some value to our readers.


Login To Post Comment