简体   繁体   中英

Mail, can't send to same email

For some odd reason if a user tries to send an email to themselves, the success function gets ran but the user never receives an email. If $toAddress and $fromAddress are the same, user never receives the email. If they're different user does.

Have read a few questions on here, saying that if the email is on the same domain as the server it gets blocked for spam. But the users email isn't on the same domain as the server? Was testing this with my gmail account. Reply-to is not the email I'm actually using, it's just dumby text.

$to = $toAddress;
$subject = 'This is an email';
$message = $message;
$headers = 'From: '. $fromAddress . "\r\n" .
    'Reply-To:do-not-reply@gmail.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion() . "\r\n" .
    'MIME-Version: 1.0' . "\r\n" .
    'Content-Type: text/html; charset=UTF-8';

if(mail($to, $subject, $message, $headers)){
    echo '{"status": "success", "senderAddress": "' . $_SERVER['REMOTE_ADDR'] . '", "content": "' . $_POST['toAddress'] . '"}';
} else {
    echo '{"status": "fail", "toAddress": ' . $toAddress . '", "fromAddress": "' . $fromAddress . '"}';
}

Exclude the headers in the mail() function and try it. The headers are triggering GMail's filtering system. If a mail is sent from Gmail, there is a certain Domain-Key based authentication that verifies the identity of the senders.

you might need to Create a TXT DNS record containing this text:

v=spf1 include:_spf.google.com ~all

in your DNS server, to authorize your domain sending email.

Due to filtering systems withing Gmail and Hotmail, when using yourself as the receiver and the from it was going directly into spam within Gmail and Hotmail. With Gmail if the two values are different it would go into your inbox while hotmail will still count it as spam.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM