Solved

PHP mail() not being delivered to gmail

Posted on 2016-07-23
19
53 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 21

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
 
LVL 21

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 82

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 82

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 21

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 108

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Easy CSR creation in Exchange 2007,2010 and 2013
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 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

13 Experts available now in Live!

Get 1:1 Help Now