Fixing a broken contact form on a Joomla site

Recently, I switched most of my sites to another server.

After about a week of not receiving any messages through the contact form on one of them, I suddenly realized… “ya know… it’s been a while”. I tried sending myself a test message through the contact form, and never received it. Sending from another email account worked though. Strange…..

Before going any further it’s worth noting that I’m using Google Apps on the aforementioned site for mail (gmail for domains).

To narrow down the cause, I did a couple things. First, I came across a little script on the Joomla forums (thanks to “ChiefGoFor”). It basically tests the PHP mail function (which Joomla uses by default) and looks like this:

<?php
mail(“youremail@domain.com”, “Testing PHP mail”, “Email sent successfully”);
echo “script complete.”;
?>

I made a file called “testmail.php”, plunked that code in, changed the email address to a hotmail one that I own, and opened in in my web browser. It worked.

——

Next I tried changing the email address it sends to from within the Joomla site, again, pointing it to the hotmail one I tried above.

It worked!

Problem was obviously either Google not accepting messages from the server, or the server not sending to Google for some reason.

I popped open WHM, and ran the “Mail Troubleshooter” (under the “Email” section in WHM). When I typed in the address hosted through Google Apps, it spit out the following message:

virtual_aliases via virtual_aliases router forced address failure

Fun.

I tried entering a hotmail address, and it showed the proper MX lookups through Hotmail.

Now all the pieces were falling together.

Here’s what was happening….

  • The DNS isn’t hosted on the web server in my case. It’s hosted elsewhere. It’s properly set up (MX records and all).
  • The web server however doesn’t look at the DNS server for a site contained on the web server. After all, why would it spend the time to look itself up?
  • In short, while MX records were properly set up on the DNS server, they also have to be set up on the web server if it ever sends mail to an email address that reflects a domain on the server which is hosted elsewhere.

I’ll draw a little picture to explain it a little better.

web-server-dns-email-process-google-apps

As you can see from my wonderful drawing, if your mail is hosted somewhere else, it won’t matter that your separately-hosted DNS server was set up correctly – you’ll still have to add the MX entries to the web server (otherwise it’ll just look at itself).

The good news is that for those who self-host their DNS, WHM/CPanel will pick up the MX entries when you add them to the zone file.

For everyone else, MX entries can be added easily in CPanel’s “MX Entry” section.