简体   繁体   中英

php's mails not sended on gmail.com

I have this code

mail($to, 'Some Subject', 'message');

If $to is gmail.com mail server addres, mail is not sended, but If $to is some other mail server, for example mail.ru , message send successfully.

What may reason?

GMail blocks little servers because they tend to send most of the spam.

Edit: but I believe I made it work once, one second, I am searching the relevant code!

I did cut out a bit, but should still work.

public function send($sName, $sMail, $sSubject, $aTo, $sContent, $bHtml){
    $this->mailer = 'X-Mailer: PHP/' . \phpversion(). "\n";
    $this->ip = 'X-Sender-IP:' . $_SERVER['REMOTE_ADDR'] . "\n";

    $this->from = 'From:' . $sName . '<' . $sMail . ">\n";
    $this->reply = 'Reply-To:' . $sMail . "\n";
    $this->contentType = "Content-Type: text/html\nContent-Transfer-Encoding: 8bit\n\n";

    $this->from .= $this->reply;
    $this->from .= $this->mailer;
    $this->from .= $this->ip;
    $aAttach = $this->checkAttachement();
    $this->from .= $this->contentType;

    foreach($aTo as $to){
        $to = \trim($to);
        if($to != "" && \strlen($to) > 5){
            mail($to, $sSubject, $sContent, $this->from);
        }
    }
}

Check your Spam box. Because services like this are used to send mass emails, GMail will usually block it.

In your public domain DNS record for the domain your from email adress uses (like noreply@mydomain.ru), you need to create an SPF Record for your sending server/ip.

An SPF record might look like this:

v=spf1 include:my-php-server.ru ~all

See this: http://en.wikipedia.org/wiki/Sender_Policy_Framework

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