Sending Emails using Gmail

如果要利用phpmailer由Gmail發信,要設定google account:

未開啟兩階段認證:

要啟用”允許安全性較低的應用程式”

注意: 有可能在帳戶中找不到這個選項,應該是有使用G Suite而且權限被Dsiable, G Suite的設定參考這一篇


image-24

$this->mail= new PHPMailer();
$this->mail->From = $this->sender['email'];
$this->mail->FromName = $this->sender['name'];
$this->mail->IsHTML(true);

$this->mail->isSMTP();
$this->mail->Host = $this->smtp['host'];
$this->mail->SMTPAuth = true;
$this->mail->Username = $this->smtp['user_name'];
$this->mail->Password = $this->smtp['password'];
$this->mail->SMTPSecure = 'tls';
$this->mail->CharSet = "utf-8";
$this->mail->Encoding = "base64";
$this->mail->Port = 587;
$this->mail->SMTPDebug = false;

 

已啟用兩階段認證:

要取得應用程式密碼