PHP Mail Issues and DNS
1. A VPS user believes that the PHP mail function is not working or that there is something wrong with the mail sending script (Contact Us form, registration form, or an order form which sends an email).
2. A user is having trouble sending email to other email accounts that are hosted on the same server.
In both cases, the client’s site is usually hosted on the server while email is hosted elsewhere. The site is also usually using third party nameservers (e.g. nameservers at a third-party domain registrar). The server is trying to send email locally instead of remotely where it actually exists (Google Apps, GoDaddy mail, Office365 etc).
If you think your PHP mail function is not working because you are having trouble sending email to an account on your server, you should check your DNS configuration:
- Run a DNS report of the domain on a site such as intoDNS.
- Use the output to determine if the domain is using third-party nameservers.
Third-party nameservers are nameservers whose IPs do not resolve to your server’s IP addresses. Running a DNS report will help you determine if this is the case. If it is, you likely set up an A record to have the site resolve to your server while keeping the mail exchange (MX) records set to resolve to another server.
- Move the domain for the off-server email address from /etc/localdomains to /etc/remotedomains. On cPanel servers, this can be done in WHM:
- Navigate to DNS Functions >> Edit DNS Zone, choose the domain in question and scroll to the bottom and switch to ‘Remote Mail Exchanger’. This change in WHM updates the above two files. (In certain instances even though a domain may be in /etc/remotedomains, it may still be in /etc/localdomains as well. Check to see if it is properly removed if you decide to add the file manually.)
- If you are using your own private nameservers for the domain in question, this is all that needs to be done to resolve the issue. If you are NOT using your own private nameservers, proceed to step 2.
- Delete the DNS zone file from the server because it is using third party nameservers and is not needed on the server. This local zone file is actually what is directing the server to send email locally instead of looking for it off your server. The zone file can be deleted from the following location: DNS Functions >> Delete a DNS Zone
Please note that this DNS zone file can be generated again if you ever decide to move away from third party nameservers and start using your own (e.g. ns1.yourdomain.com and ns2.yourdomain.com).
That’s it, you should now be able to send email at your domains that are hosted with third parties.