【发布时间】:2018-05-24 20:22:35
【问题描述】:
Phpmailer 配置:流明。
以前它工作?但是现在同样的配置抛出Failed to connect to server:
我是 laravel/lumen 框架的新手。这是我的 PHPmailer 配置,我不知道我在这里做错了什么。请有人在这里帮助我。
<?php
namespace App\Repositories;
use App\Repositories\BaseRepository;
use App\Models\ForgetModel;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
class ForgetRepository extends BaseRepository{
private $forget;
public function __construct(ForgetModel $forget) {
$this->forget = $forget;
}
public function save_verification_code($email,$verification_code)
{
$query = $this->forget->onMaster()
->insert(array('email'=>$email,'code'=>$verification_code));
}
public function send_forget_password_email($to,$message)
{
$subject = 'Verification code to reset your password';
$from = 'xyz@gmail.com';
$body = $message;
$headers = 'From: ' . strip_tags($from) . '\r\n';
$headers .= 'MIME-Version: 1.0\r\n';
$headers .= 'Content-Type: text/html; charset=ISO-8859-1\r\n';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = 'xyz@gmail.com';
$mail->Password = '123456';
$mail->SetFrom($from);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AddAddress($to);
if(!$mail->Send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
//echo "Message has been sent";
}
return true;
}
}
【问题讨论】:
-
阅读文档,发帖前搜索。
-
我不知道我做错了什么。我在发布问题之前进行了搜索,不知道问题出在哪里,正如我所说我是 php 和框架的新手...请帮助我@Synchro
标签: php laravel smtp phpmailer lumen