Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

PHP mail() not being delivered to gmail

I have a form on a page.  when you fill out the form and confirmation email is sent to your email address.  If you have a Gmail account or if your email is routed by Gmail the mail won't arrive.  Not even in the spam folder.  Other email addresses work fine.  Has anyone ever run into this?

  $subject = 'Email Subject';

                $headers = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
                $headers .= 'From: rgranlund@MYSITE.com' . "\r\n";
                $headers .= 'Bcc: info@MYSITE' . "\r\n";

                mail($e, $subject, $body, $headers);

Open in new window

Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

If it's rejected, your mail service (sendmail/qmail/exim/etc) might have logs with more information on what went wrong.
My experience has been that Gmail is the most likely to BE delivered. So it is odd that it would not be delivered to Gmail -- at least it is odd to me.

Do you have your own server or are you using a hosting/email service provider? If so, is that service provider GoDaddy?
Avatar of Robert Granlund

ASKER

Bluehost.  I have found various articles/posts where other people have had this issue but the solutions are all over the place.
Have you checked the Spam folder?
@kim, that was part of my original post.  It does not go to the spam folder, it just not go. I also place a CC on the email and that one works to a non-gmail account.
My PHP email demo has no problem sending to Gmail.  Have you tried it?
@dave
Essentially it is the same.
 $headers = "MIME-Version: 1.0" . "\r\n";
                $headers .= "Content-Type: text/html; charset=utf-8" . "\r\n";
                $headers .= 'From: Rock Intuit <rgranlund@MYSITE.com>' . "\r\n";
                $headers .= 'Bcc: info@MYSITE.com' . "\r\n";

                mail($e, $subject, $body, $headers, '-f rgranlund@MYSITEt.com');

Open in new window

Do you think I should try phpmailer?  Cause I am having another problem on another site where the email won't go out PERIOD if I try to add anything in addition to the FROM in the headers
If you do a basic mail() call to a Gmail address without any headers, does it work?

mail("someone@gmail.com","Test Email","Test Body");

Of course, a message like this probably WILL get put into the Spam folder, but it will at least tell you whether the delivery problem has something to do with the formatting/content of your message.
nope.  These are not going.  They will go to a regular address but not gmail
So if the basic mails aren't going, then it's probably an issue with where you're mailing from - Gmail's probably rejecting the messages for a deeper reason.

Usually if it's not even making it to the spam folder, then it might be rejected on some other grounds. I'd start with checking your server's outgoing IP on the major blacklists:

http://www.anti-abuse.org/multi-rbl-check/

Being on a blacklist could result in the message being completely blocked (not even making it to the Spam folder).

If your server IP -is- on a blacklist...

Before you say you're not a spammer, bear in mind that if you're on a shared server or if your server's IP was previously used by someone else, you might simply have inherited the issue at no fault of your own, and it'll be up to you and the blacklists to get your IP off of them.

I'd also recommend you save a copy of one of the received emails with all of its headers intact (e.g. use Thunderbird and view the source of the message and save it all to a text file) and then attach that here.
Thanks for the issue.  I have another problem where another page will only send plain text.  If I add any headers it will not go out.
Is this specific to Gmail, or is it another issue entirely? If it's a different issue, I'd suggest closing this one (if it's solved) and opening a new one for the plain text message email.
Your two 'from' addresses don't match.  Is that an email address on that server?  That can be an issue if you are sending from a server with an email address that is not on that server.
Some email handlers are particular about the "\r\n" between the headers when there are multiple. Some will accept just "\n", but others require "\r\n" (or is it "\n\r", I can't remember). But this will prevent the email from going out at all if it isn't correct. This is a limitation or restriction on your end, not on the recipient's end.
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have never had a problem using PHP to send email to Gmail accounts, but I have never tried to send anything arcane or incorrectly formatted.  Any malformation at all is a red flag, and is likely to cause rejection by the more sophisticated email programs.  Once a long time ago, there was such a thing as "bounced" email, but today rejection means "discarded silently" as if the email has gone into a black hole.  

If I want to send HTML email, I use (and recommend) Constant Contact.  There are competitors, of course, but CC has worked well for me over many years.
The code was fine. Ugggh!  The from email address had been blacklisted on a server.