Solved

PHP mail() not being delivered to gmail

Posted on 2016-07-23
19
63 Views
Last Modified: 2016-08-09
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

0
Comment
Question by:rgranlund
  • 7
  • 5
  • 3
  • +2
19 Comments
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 41726089
If it's rejected, your mail service (sendmail/qmail/exim/etc) might have logs with more information on what went wrong.
0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 41726090
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?
0
 
LVL 7

Author Comment

by:rgranlund
ID: 41726096
Bluehost.  I have found various articles/posts where other people have had this issue but the solutions are all over the place.
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 22

Expert Comment

by:Kim Walker
ID: 41726100
Have you checked the Spam folder?
0
 
LVL 7

Author Comment

by:rgranlund
ID: 41726104
@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.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 41726116
My PHP email demo has no problem sending to Gmail.  Have you tried it?
0
 
LVL 7

Author Comment

by:rgranlund
ID: 41726132
@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

0
 
LVL 7

Author Comment

by:rgranlund
ID: 41726134
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
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 41726136
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.
0
 
LVL 7

Author Comment

by:rgranlund
ID: 41726138
nope.  These are not going.  They will go to a regular address but not gmail
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 41726141
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.
0
 
LVL 7

Author Comment

by:rgranlund
ID: 41726144
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.
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 41726152
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.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 41726161
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.
0
 
LVL 22

Expert Comment

by:Kim Walker
ID: 41726182
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.
0
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 41726617
@Kim - It's "\r\n" - Carriage Return + New Line. A handy way of remembering the order is the phrase "Return to the Next line." Also, I agree totally with you - using \n as the line ending in mail headers can result in undesired behavior.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 41727533
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.
0
 
LVL 7

Author Comment

by:rgranlund
ID: 41731716
The code was fine. Ugggh!  The from email address had been blacklisted on a server.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
The new Gmail Phishing Scam going around is surprising even the savviest of users with its sophisticated techniques.
The viewer will learn how to dynamically set the form action using jQuery.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now