Emails sent via PHPMailer getting filtered to spam in Gmail and Yahoo

I’m having trouble with my PHPMailer setup where messages keep landing in spam folders for Gmail and Yahoo users. The emails send successfully but recipients don’t see them in their inbox. I’ve tried adjusting some settings but nothing seems to work. Has anyone else faced this issue? Here’s my current configuration:

$mailer->addCustomHeader('Reply-to: [email protected]');
$mailer->setFrom('[email protected]', 'Company Support');
$mailer->isSendmail();
$mailer->addReplyTo('[email protected]');
$mailer->addAddress($recipient, $recipientName);
$mailer->Subject = $emailSubject;
$mailer->AltBody = 'Please use an HTML-compatible email client to view this message';
$mailer->WordWrap = 80;
$content = 'Welcome to our service';
$mailer->msgHTML($content);
$mailer->isHTML(true);

What could be causing this spam filtering issue?

check your server’s hostname config - this got me once. if your hostname doesn’t match your sending domain, gmail auto-flags it. that generic ‘welcome to our service’ stuff screams spam too. add real user data or write it more conversationally. start small with engaged users to warm up your sending reputation. don’t blast everyone right away.

Had this exact same problem last year - super frustrating. Missing SPF and DKIM records were killing me. Gmail and Yahoo cracked down hard on email authentication lately. You need proper SPF, DKIM, and DMARC records set up for your domain. Also, ditch isSendmail() - it’s problematic. Switch to SMTP with authentication instead. Make sure your reply-to header matches your from address domain, and check if your server’s IP got blacklisted. I used MXToolbox to check my domain reputation and found tons of issues I didn’t know about. Fixed the DNS records, switched to authenticated SMTP, and my delivery rates shot up.

Your code’s got multiple issues triggering spam filters. First, fix that Reply-to header - you’re using addCustomHeader when you already have addReplyTo. Drop the duplicate line. Your content looks like bot-generated garbage, which filters instantly flag. Add real personalization and actual meaningful text. That AltBody screams template email too. Here’s the big one though - check your hosting setup. Shared hosting usually has trash sender reputation. I moved to a VPS with dedicated IP and deliverability jumped immediately. Also make sure your domain has reverse DNS configured properly - people always forget this but it’s huge for getting through filters. Run everything through mail-tester.com first to check your spam score before sending anything.