Issues with PHP mail function when sending from Yahoo address to Gmail recipient

I’m working on a contact form that uses PHP’s built-in mail function. Most email combinations work perfectly fine, including Gmail to Yahoo transfers. However, I’m running into a specific issue when trying to send emails from a Yahoo address to a Gmail recipient.

Here’s a simple example that demonstrates the problem:

mail("[email protected]", $title, $content, "From: [email protected]");

This particular scenario fails to deliver the message. Has anyone encountered this issue before? What could be causing Yahoo to Gmail emails to fail while other combinations work normally?

Here’s my complete implementation:

<?php
$mail_headers = "MIME-Version: 1.0" . "\r\n";
$mail_headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$mail_headers .= "From: ".$sender_email;
$email_subject = $contact_name." - ".$email_title;
$email_body = nl2br($email_content);
$email_body = $email_body."<br /><br /><br />".$user_name."<br />".$contact_number."<br />".$website;
$email_body = wordwrap($email_body, 70, "\r\n");
if(mail($recipient_address, $email_subject, $email_body, $mail_headers)){
    echo "<p class='success'><span></span> ".$success_msg."</p>";
}
else{
    echo "<p class='error'><span></span> Something went wrong, please try again</p>";
};
?>

This is definitely an email authentication issue. Yahoo has really strict SPF and DKIM policies, and when you use PHP’s basic mail function with a Yahoo sender address, Gmail can’t verify that your server’s actually allowed to send emails for Yahoo. Gmail’s spam filters are pretty smart - they’ll reject or quarantine emails that don’t pass these checks. Your server isn’t Yahoo’s server, so it doesn’t have the right credentials to send emails pretending to be from Yahoo. That mismatch triggers anti-spoofing protection. I’ve run into this exact problem before. Switching to proper SMTP completely fixed it for me. Try using PHPMailer with Yahoo’s SMTP settings, or authenticate through your hosting provider’s mail server instead of the basic mail function. You could also set the From header to your domain’s email address and put the original sender info in the Reply-To header or email body.

Had the same issue a few months back. It’s usually reverse DNS lookups failing. Gmail does extra verification checks on Yahoo addresses, and if your server’s IP doesn’t have proper reverse DNS, delivery fails silently. It’s not just authentication - Gmail’s filtering system also cares about your server’s reputation. I fixed it by setting up proper PTR records pointing back to my domain. Also check if your server’s IP got blacklisted. Yahoo addresses trigger stricter content filtering too, so even small header or content formatting issues can cause rejection. Test with a neutral domain first to see if Yahoo’s specifically the problem.

yahoo’s cracking down hard on email policies right now. PHP’s mail() function spoofs sender addresses without proper auth, so gmail flags it as phishing and dumps it. quick fix: don’t put yahoo in the from field. use your domain’s email in from and stick the yahoo address in reply-to instead. just did this last week - works perfectly.