Search code examples
phphtmlemailgmail

PHP Web Form Not Sending To Gmail Email


I have a php form that I made and when someone fills out the form it works fine with all other email accounts (yahoo, hotmail, @mydomain.com, etc) but when it comes to sending the email to a gmail user, the email never comes through, not even in the spam box.

            $from = $email;

            //Testing Below
            //$headers = 'From:[email protected]' . "\r\n"; 
            $headers .= "From: $from \n";
            $headers .= " MIME-Version: 1.0\r\n ";
            $headers .= " Content-Type: text/html; charset=ISO-8859-1\r\n ";

            //Mail The Message
            mail($to, $subject, $message, $headers);

The code above will not send to gmail but will work for all other email accounts. This one (below) will work for gmail but of course then I don't have the option of html in the email.

            $headers = 'From:[email protected]' . "\r\n"; 
            //$headers .= "From: $from \n";
            //$headers .= " MIME-Version: 1.0\r\n ";
            //$headers .= " Content-Type: text/html; charset=ISO-8859-1\r\n ";

            //Mail The Message
            mail($to, $subject, $message, $headers);

So basically when I add the MIME and Content type to the headers variable it wont send to a gmail account.

Thanks in advance!


Solution

  • I have replied a question not too long ago related to this. It might have to do with the gmail's email filtering, maybe you are getting too high spam score so it's not even getting into the spam folder, this could be caused by not having correct dns configuration / keys and trying to use html at the same time.

    I leave a link to the other answer (It's quite long, and not as easy as you would imagine xD):

    PHP and Gmail spam filter

    Hope it helps you.