Why Emails Fail to Send
When users configure email or contact forms to work with cPanel, messages from forms should be delivered if scripted properly. However, email delivery can fail for many reasons — from misconfigured DNS records to server-level restrictions.
MX Records: Local vs Remote
If you use third-party MX records (Google Workspace, Microsoft 365, Yahoo), your domain needs to be configured to look for remote MX records rather than local ones.
- VPS or Dedicated Server: Configure this in the mail routing settings of your control panel (WHM/cPanel)
- Shared Hosting: You may need to contact your hosting provider to switch from local to remote mail exchange
In cPanel, go to Email Routing and select "Remote Mail Exchanger" for the domain using external email.
SPF, DKIM, and DMARC
These DNS records are critical for email deliverability. Without them, emails often land in spam or get rejected entirely.
SPF (Sender Policy Framework)
Tells receiving servers which IP addresses are authorized to send email for your domain.
# Example SPF record (TXT record on your domain)
v=spf1 +a +mx +ip4:YOUR.SERVER.IP include:_spf.google.com ~all
DKIM (DomainKeys Identified Mail)
Adds a cryptographic signature to outgoing emails so receivers can verify the message wasn't tampered with. Enable DKIM in cPanel under Email Deliverability.
DMARC (Domain-based Message Authentication)
Tells receiving servers what to do when SPF or DKIM checks fail.
# Basic DMARC record (TXT record at _dmarc.yourdomain.com)
v=DMARC1; p=quarantine; rua=mailto:admin@yourdomain.com
PHP mail() Troubleshooting
The built-in PHP mail() function is the simplest way to send email from a script, but it has limitations on many shared hosts.
Basic Mail Test Script
<?php
$to = "test@example.com";
$subject = "Test Email from PHP";
$message = "If you receive this, PHP mail() is working.";
$headers = "From: webmaster@yourdomain.com\r\n";
$headers .= "Reply-To: webmaster@yourdomain.com\r\n";
if (mail($to, $subject, $message, $headers)) {
echo "Email sent successfully.";
} else {
echo "Email failed to send.";
// Check the mail log for details
}
?>
The From: header must match a valid email address on your domain. Many servers reject emails where the From address doesn't match the sending domain.
SMTP vs PHP mail()
For more reliable delivery, use SMTP authentication instead of PHP's mail() function:
- PHP mail() — Uses the server's local mail transfer agent. Simple but unreliable, emails often flagged as spam.
- SMTP — Authenticates with a mail server using credentials. More reliable, better deliverability, required by services like Gmail and Outlook.
For WordPress, install a plugin like WP Mail SMTP to route all emails through an authenticated SMTP connection.
Contact Form Debugging
Verify Form Action
Ensure the form's action attribute points to the correct processing script and that the method is POST.
Check Server Mail Logs
Review /var/log/mail.log or /var/log/exim_mainlog (cPanel) for delivery attempts and error messages.
# Tail the mail log in real-time
tail -f /var/log/exim_mainlog | grep yourdomain.com
Test Deliverability
Use tools like Mail Tester (mail-tester.com) to send a test email and get a spam score with detailed recommendations.
If your contact form uses a plugin like Contact Form 7, check the "Additional Headers" tab. A missing or incorrect Reply-To header is a common cause of delivery failures.