Solved

PHP mail() not being delivered to gmail

Posted on 2016-07-23
19
82 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
  • +2
19 Comments
 
LVL 35

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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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 35

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 35

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 35

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 35

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 110

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
As cyber crime continues to grow in both numbers and sophistication, a troubling trend of optimization has emerged over the last year.
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 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