I have a contact form written in PHP that works fine when sending emails to most providers, but Gmail addresses never receive the messages. The emails don’t show up in spam folders either. I’m running this on a dedicated server with Linux and WHM. Since I’m not really experienced with email delivery issues, could someone help me figure out what needs to be changed in my code to make it work with Gmail? Here’s what I’m currently using:
This happens all the time with Gmail and the native mail() function. Gmail’s probably silently rejecting your emails because they look like they’re coming from an unverified source. You’re setting the From header to the user’s email but sending through your server - Gmail thinks you’re spoofing. I hit this exact issue last year. Fixed it by changing the From header to my domain’s email and putting the user’s email in Reply-To instead. Also check your server’s reverse DNS setup - Gmail dumps emails from servers without proper rDNS. Adding a Return-Path header helps with deliverability too.
Gmail’s authentication rules are strict, and PHP’s basic mail() function usually can’t meet them. Your server probably doesn’t have SPF, DKIM, or DMARC records set up - Gmail checks for all of these. I’ve had success switching to PHPMailer with SMTP for this exact problem. Make sure your email service (like Postfix) is configured properly, or just use a third-party SMTP service like SendGrid or Mailgun. The mail() function lacks the authentication headers Gmail requires. It’s also wise to check your server’s IP reputation, as flagged IPs may lead to your emails not reaching even the spam folder.
Check your server logs first - they’ll show why Gmail’s bouncing your emails. Gmail automatically blocks tons of shared hosting IPs. Add proper MIME headers and make sure your server hostname matches your domain. I had the same problem and it turned out my server was using the default hostname from my hosting provider. Gmail hated that.