tags:

views:

1833

answers:

5

I have 2 sites where mail is sent to two vanity gmail accounts. I'm using PHP to handle the mail, but the mail is not showing up at gmail (not in spam/junk, it just doesn't show up). If I switch the PHP to send to my personal hotmail account, the mail shows up. Same for a personal email account through my ISP.

The mail used to show up at those 2 vanity gmail accounts, any ideas why they would just stop?

+7  A: 

There is a possibility you did not set proper header data, and those emails are blocked even before reaching spam folder.

Try adding something like this:

$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]';

This is the fourth parameter of mail() function.

Thinker
I agree, this is possible.
Matt Refghi
What would the proper header data be? I'm not setting any headers:$to = '[email protected]';$subject = 'my subject';$body = urlencode($comments);mail($to, $subject, urldecode($body), "From: {$_POST['email']}");
And to reiterate, the mail used to go through to both accounts. No code changes have been made.
Also worth checking the Google development blogs, see if they changed anything. If they started checking SPF it could cause problems.
James Socol
+3  A: 

I have encountered problems in the past where certain free email providers would not receive any email from my servers.

I found that a few things can be the culprit, on top of putting the correct headers in the actual message:

  • Make sure your server is configured for reverse dns lookup
  • Make sure you are not running an open smtp relay
  • Make sure your server did not wind up in any email blacklists (if you had an open relay, you probably got blacklisted.

Chances are, PHP is sending the email just fine, but the Google servers are rejecting any messages coming from your server.

You can test this by doing a quick:

mail -s Test [email protected] < /dev/null

If your server is okay, you will receive a message in your gmail, if you don't, PHP isn't the problem.

WerkkreW
+2  A: 

I've found having a proper SPF record for your domain really helps

http://www.openspf.org/SPF_Record_Syntax

Evert
A: 

Seems more likely that this is a server configuration issue and not a PHP issue.

As a side note I've found gmail more tolerant than our local system, so I've been able to get messages out to my gmail account, but not my account on the hosting domain.

I don't think Google uses third-party black lists, but they do care about server configuration (does it identify itself correctly, have matching SPF and RDNS records, respond to commands properly). You might try a couple of testing services like this or this.

acrosman
A: 

I see it is too late but ... following code is working for gmail.

<html>
Mail Responder:<br><br>
<?php 
$to = $_REQUEST['MyEmail'] ; 
$subject = $_REQUEST['subject'] ; 
$greeting = $_REQUEST['greeting'] ; 
$realname = $_REQUEST['realname'] ;
$HisEmail = $_REQUEST['HisEmail'] ; 
$message = $_REQUEST['message'] ;
$headers = 'From: '.$HisEmail;  
//$headers = 'From: $HisEmail' . "\r\n" .
//'Reply-To: [email protected]';

$send = mail($to, $subject, $greeting."\n"."\n".$realname."\n"."\n".$HisEmail."\n"."\n".$message, $headers );
if ($send)
$mailReturns = "Mail sent successfully.";
else
$mailReturns = "Mail sent failed.";

?>
<?php echo $mailReturns; ?>
</html>
Rahul2047