PHP mail not showing up at Gmail but shows up at Hotmail and other 3rd party/ISP account

后端 未结 5 1885
无人及你
无人及你 2020-12-11 16:44

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\

相关标签:
5条回答
  • 2020-12-11 17:01

    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: some@email.com';
    
    $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>
    
    0 讨论(0)
  • 2020-12-11 17:06

    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 you@gmail.com < /dev/null
    

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

    0 讨论(0)
  • 2020-12-11 17:07

    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: your@email.com' . "\r\n" .
    'Reply-To: some@email.com';
    

    This is the fourth parameter of mail() function.

    0 讨论(0)
  • 2020-12-11 17:16

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

    http://www.openspf.org/SPF_Record_Syntax

    0 讨论(0)
  • 2020-12-11 17:18

    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.

    0 讨论(0)
提交回复
热议问题