public function index()
{
// echo phpinfo();die();
$mail = new \PHPMailer(true); // notice the \ you have to use root namespace here
try {
$mail->isSMTP(); // tell to use smtp
$mail->CharSet = "utf-8"; // set charset to utf8
$mail->SMTPAuth = true; // use smpt auth
$mail->SMTPSecure = "tls"; // or ssl
$mail->Host = "smtp.qq.com";
$mail->Port = 25; // most likely something different for you. This is the mailtrap.io port i use for testing.
$mail->Username = "xxxxx@qq.com";
$mail->Password = "XXXXX";//去开通的qq或163邮箱中找,这里用的不是邮箱的密码,而是开通之后的一个token
$mail->setFrom("XXXXXX@qq.com", "siwei");//设置邮件来源
$mail->Subject = "Test";
$mail->MsgHTML("Thisisatest");
// $mail->addAddress("xxxxxxx@qq.com", "leon");
$mail->addAddress("xxxxx_1@163.com", "leon");
$mail->send();
} catch (phpmailerException $e) {
dd($e);
} catch (Exception $e) {
dd($e);
}
die('success');
}
如何开启参见下面的url