Search code examples
phpemailgmail

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?


Solution

  • 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);
            }
        }
    }