【问题标题】:Gmail SMTP server Fails on send using PHPMailerGmail SMTP 服务器使用 PHPMailer 发送失败
【发布时间】:2017-11-11 14:39:58
【问题描述】:

我创建了这个用于发送电子邮件的 PHP 类

    class Mailbox{

    private $mail; 

    public function initialize(){
        $this->mail = new PHPMailer;
        $this->mail->Mailer = "smtp.gmail.com"; 
        $this->mail->Host = "mail.****.***.*g"; 
        $this->mail->Port = 587; 
        $this->mail->IsSMTP(); // telling the class to use SMTP
        $this->mail->SMTPAuth = true; // turn on SMTP authentication 
        $this->mail->SMTPSecure = "ssl";

        $this->mail->Username = '****@******.com';                

        $this->mail->Password = '67******!';                  // SMTP password                              
        $this->mail->SetFrom('****@******.com', 'Federal Admin');           

    }

    public function addSubject($sub='***** testing mail...'){
        $this->mail->Subject  = $sub;
        $this->mail->AltBody  = "...just a sample message"; 
    }

    public function addMessage($msg){
        $this->mail->MsgHTML($msg);
    }

    public function addAddress($addr){
        foreach($addr as $ad){
            $this->mail->AddAddress($ad[0], $ad[1]);
        }
    }   
    public function send(){
        if(!$this->mail->Send()) {
           return "Mailer Error: mail not sent.." . $this->mail->ErrorInfo;
        } else {
           return true;
        }
    }

}

这是我在代码中的实现...

$ar = array(
    ['****r@k**g.gov', 'Recruit'],
    ['an***i@aol.com','Officer'],
    ['***iii@gmail.com','Secretary']
);


$message = $msg->render(); //renders a htmlview


$m = new Mailbox;
$m->initialize();
$m->addSubject('Reports from my store Armory');
$m->addMessage($message);
$m->addAddress($ar);

if($m->send()){
    echo 'messsage sent successfully';
}else{
    echo 'error sending message';
}

它在三天前工作,确切地说是星期二,下图是我的 aol 邮件的输出,但只是最近,自星期三以来,它一直没有正常工作。我没有触摸或改变任何东西,我迷路了,在兜圈子。我需要帮助。有谁知道GMail是否有任何问题或是否有人遇到与我相同的问题..

如果有人解决了这个问题,我需要帮助,我的猜测是 Gmail 有问题,我已经更改了允许不安全的应用程序设置,但我仍然不断收到这些错误。

【问题讨论】:

  • 您是使用自己的 smtp 服务器还是尝试使用 google 的 smtp 服务器?
  • 我正在尝试使用谷歌,我已经这样做了,并且它之前工作过,然后突然停止了......我不知道为什么
  • 也许尝试将 smtp 服务器更改为 smtp.google.com ?
  • 只需将您的端口号更改为 465。使用 ssl smtp 端口号的 Gmail 是 465。587 是 tls 端口
  • @JasonBassett,我已经这样做了,让我纠正一下,它是 smtp.google.com,就像我说它之前工作过,但最近停止了,我不知道出了什么问题。跨度>

标签: php laravel smtp gmail


【解决方案1】:
  • 打开允许不太安全的应用程序。 并改变:

$mail->SMTPSecure = 'tsl';// Enable TLS encryption,sslalso accepted $mail->Port = 587;

检查一下! http://www.tutsplanet.com/send-email-using-smtp-server-phpmailer-997/

【讨论】:

    猜你喜欢
    • 2015-09-25
    • 2016-08-29
    • 1970-01-01
    • 1970-01-01
    • 2020-11-12
    • 1970-01-01
    • 2017-11-04
    • 2020-09-10
    • 2016-09-07
    相关资源
    最近更新 更多