Email notifications are a crucial part of any WordPress website, whether for user registrations, contact forms, or order confirmations. However, many users face an issue where PHP mail (mail()) stops working. If you recently installed WordPress and encountered the “Email not sent” error, this guide will help you understand the possible reasons and solutions.
Common Reasons Why PHP Mail is Not Working
1. Hosting Provider Restrictions
Many web hosting providers disable PHP mail for security reasons. If your emails were working before and suddenly stopped after reinstalling WordPress, your host may have updated their policy.
How to Check:
- Contact your hosting provider and ask if PHP mail is allowed.
- Some shared hosts require you to use SMTP instead.
2. Missing Mail Server on Your Hosting
If you’re using a VPS or dedicated server, a mail server such as Sendmail or Postfix may not be installed.
Solution:
- Check if a mail server is installed by running this command in your terminal (for Linux servers):
which sendmail - If not installed, install Postfix:
sudo apt-get install postfix
3. Incorrect WordPress Email Settings
WordPress by default uses wordpress@yourdomain.com as the sender email. If your mail server does not recognize this, emails may not be sent.
Solution:
- Install and activate the WP Mail SMTP plugin.
- Set a proper “From Email” address like admin@yourdomain.com.
- Use a real email address that exists in your hosting’s email system.
4. Emails Marked as Spam or Blocked by Mail Providers
If emails are being sent but not received, they might be landing in the spam folder or being blocked by email providers.
Solution:
- Check your email spam folder.
- Use an email blacklist checker like MXToolBox to see if your domain or IP is blacklisted.
- Set up SPF, DKIM, and DMARC records in your DNS settings.
5. Security Plugins Blocking Emails
Some WordPress security plugins block outgoing emails as a precautionary measure.
Solution:
- Temporarily disable security plugins and test the email functionality.
- If emails start working, configure the plugin to allow email sending.
6. SMTP Not Configured (Recommended Fix)
SMTP (Simple Mail Transfer Protocol) is a more reliable way to send emails compared to PHP mail.
How to Set Up SMTP in WordPress:
- Install and activate the WP Mail SMTP plugin.
- Go to WP Mail SMTP > Settings.
- Enter your SMTP details:
- SMTP Host: smtp.gmail.com (for Gmail) or your provider’s SMTP server.
- SMTP Port: 587 (for TLS) or 465 (for SSL).
- Encryption: TLS or SSL.
- SMTP Username: Your full email address.
- SMTP Password: Your email account password or an app-specific password.
- Save changes and test by sending an email.
7. Testing PHP Mail Functionality
If you want to check whether your server can send mail, create a simple test script:
<?php
$to = “your@email.com”;
$subject = “Test Email”;
$message = “This is a test email.”;
$headers = “From: noreply@yourdomain.com”;
if(mail($to, $subject, $message, $headers)) {
echo “Mail sent successfully.”;
} else {
echo “Mail sending failed.”;
}
?>
- Save this as testmail.php and upload it to your server.
- Open it in your browser (yourdomain.com/testmail.php).
- If it fails, your server does not support PHP mail.
Conclusion
If PHP mail isn’t working in WordPress, the best long-term solution is to switch to SMTP using the WP Mail SMTP plugin. This method ensures reliable email delivery and prevents your emails from being marked as spam. If you’re on a VPS or dedicated server, make sure your mail server is correctly set up.
Do you have any questions or need further help? Let us know in the comments!
