PHPMailer出现问题.无法连接到服务器? [英] Problem with PHPMailer.Failed to connect to server?
本文介绍了PHPMailer出现问题.无法连接到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是PHP的新秀.我连接了PHPMailer.我正在训练中发送电子邮件,但出现错误
I'm rookie in PHP. I connected PHPMailer. I was training send an email, but I got error
我的代码
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require ("vendor/autoload.php");
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = true;
$mail->Username = ''; -The mail I'm trying to send an email to
$mail->Password = ''; - password of this email
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('', 'admin'); The mail I'm trying to send an email to
$mail->addAddress('', 'Recipient'); -recipient
$mail->isHTML(true);
$mail->Subject = 'Test Mail Subject!';
$mail->Body = 'This is SMTP Email Test';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
我想提前说一下这封邮件是不安全的.我也尝试更改STMPSECURE(tls)
I want to say in advance that this mail is not secure. I also tried change STMPSECURE(tls)
我知道了
SMTP错误:无法连接到服务器:连接被拒绝(111)
SMTP ERROR: Failed to connect to server: Connection refused (111)
推荐答案
您必须在SMTP服务器上拥有一个帐户,例如:smtp.googlemail.com
(也是最容易获得的),因此您可以这样设置:
You must have an account on a SMTP server, for example: smtp.googlemail.com
(and easiest to get), so you can set like this:
$mail->Host = 'smtp.googlemail.com';
$mail->SMTPAuth = true;
$mail->Username = 'YOUR_GOOGLE_USERNAME'; // NOT email address to send to
$mail->Password = 'YOUR_GOOGLE_PASSWORD';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
这篇关于PHPMailer出现问题.无法连接到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文