Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从本地主机向用户发送几封邮件后SMTP显示错误_Php_Smtp_Phpmailer - Fatal编程技术网

Php 从本地主机向用户发送几封邮件后SMTP显示错误

Php 从本地主机向用户发送几封邮件后SMTP显示错误,php,smtp,phpmailer,Php,Smtp,Phpmailer,我正在使用phpmailer和smtp将邮件从本地主机发送到gmail。问题是首先我发送邮件,它工作正常,但现在它给smtp连接失败。这是我的密码。我是新手,请帮帮我 $mail = new PHPMailer\PHPMailer\PHPMailer(); $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp.gmail.com';

我正在使用phpmailer和smtp将邮件从本地主机发送到gmail。问题是首先我发送邮件,它工作正常,但现在它给smtp连接失败。这是我的密码。我是新手,请帮帮我

$mail = new PHPMailer\PHPMailer\PHPMailer();

    $mail->isSMTP();                            // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';             // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                     // Enable SMTP authentication
    $mail->Username = 'smag.ghaznavi1@gmail.com';          // SMTP username
    $mail->Password = 'mypassword'; // SMTP password
    $mail->SMTPSecure = 'tls';                  // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                          // TCP port to connect to
    $mail->SMTPDebug=2;
    $mail->setFrom('info@example.com', 'PMS');
    //$mail->addReplyTo('info@example.com', 'CodexWorld');
    $mail->addAddress('smag.ghaznavi1@gmail.com');   // Add a recipient
    //$mail->addCC('cc@example.com');
    //$mail->addBCC('bcc@example.com');

    $mail->isHTML(true);  // Set email format to HTML

    $bodyContent = '<h1>Your password reset link</h1>';
    $bodyContent .= "Dear user,\n\nIf this e-mail does not apply to you please ignore it. It appears that you have requested a password reset at our website www.yoursitehere.com\n\nTo reset your password, please click the link below. If you cannot click it, please paste it into your web browser's address bar.\n\n" . $pwrurl . "\n\nThanks,\nThe Administration";

    $mail->Subject = 'Email from Project Management System Admin';
    $mail->Body    = $bodyContent;

    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }



smag.ghaznavi1@gmail.com2018-07-04 16:43:58 SERVER -> CLIENT: 220 
smtp.gmail.com ESMTP o4-v6sm5724500wmo.20 - gsmtp
2018-07-04 16:43:58 CLIENT -> SERVER: EHLO localhost
2018-07-04 16:43:58 SERVER -> CLIENT: 250-smtp.gmail.com at your service, 
[39.54.130.23]250-SIZE 35882577250-8BITMIME250-STARTTLS250- 
ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
2018-07-04 16:43:58 CLIENT -> SERVER: STARTTLS
2018-07-04 16:43:58 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2018-07-04 16:43:59 CLIENT -> SERVER: QUIT
2018-07-04 16:43:59 SERVER -> CLIENT: 
2018-07-04 16:43:59 SMTP ERROR: QUIT command failed: 
SMTP connect() failed. 
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. 
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
$mail=new PHPMailer\PHPMailer\PHPMailer();
$mail->isSMTP();//将邮件程序设置为使用SMTP
$mail->Host='smtp.gmail.com';//指定主SMTP服务器和备份SMTP服务器
$mail->SMTPAuth=true;//启用SMTP身份验证
$mail->Username='smag。ghaznavi1@gmail.com';          // SMTP用户名
$mail->Password='mypassword';//SMTP密码
$mail->SMTPSecure='tls';//启用TLS加密,也接受'ssl'
$mail->Port=587;//要连接到的TCP端口
$mail->SMTPDebug=2;
$mail->setFrom('info@example.com","PMS",;
//$mail->addReplyTo('info@example.com","CodexWorld",;
$mail->addAddress('smag。ghaznavi1@gmail.com');   // 添加收件人
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
$mail->isHTML(正确);//将电子邮件格式设置为HTML
$bodyContent='您的密码重置链接';
$bodyContent.=“亲爱的用户,\n\n如果此电子邮件不适用于您,请忽略它。您似乎已在我们的网站www.yoursitehere.com请求重置密码\n\n要重置密码,请单击下面的链接。如果无法单击,请将其粘贴到web浏览器的地址栏中。\n\n”$pwrurl。“\n\n银行,\n管理”;
$mail->Subject='来自项目管理系统管理员的电子邮件';
$mail->Body=$bodyContent;
如果(!$mail->send()){
echo“无法发送消息”;
回显“邮件错误:”。$mail->ErrorInfo;
}否则{
回音“消息已发送”;
}
斯马格。ghaznavi1@gmail.com2018-07-04 16:43:58服务器->客户端:220
smtp.gmail.com ESMTP o4-v6sm5724500wmo.20-gsmtp
2018-07-04 16:43:58客户端->服务器:EHLO本地主机
2018-07-04 16:43:58服务器->客户端:250-smtp.gmail.com为您服务,
[39.54.130.23]250-35882577250-8BITMEME250-STARTTLS250-
增强状态代码250-管道250 SMTPUTF8
2018-07-04 16:43:58客户端->服务器:开始
2018-07-04 16:43:58服务器->客户端:220 2.0.0准备启动TLS
SMTP错误:无法连接到SMTP主机。
2018-07-04 16:43:59客户端->服务器:退出
2018-07-04 16:43:59服务器->客户端:
2018-07-04 16:43:59 SMTP错误:退出命令失败:
SMTP连接()失败。
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
无法发送邮件。邮件程序错误:SMTP connect()失败。
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
检查您的谷歌帐户中是否启用了“允许不太安全的应用”

另外,请尝试输入您的google帐户并访问页面“displayCaptcha”-


您应该提供代码以了解问题所在

无法启动TLS,这通常表明您的CA证书已过期,尤其是在使用Gmail时。这与“不太安全的应用程序”设置或验证码问题无关——尽管你以后可能会遇到这些问题


请按照描述此错误的错误消息进行操作,并告诉您如何修复此错误(通过更新CA证书-而不是通过禁用证书验证!)。这很奇怪,几乎就好像那个链接纯粹是为了帮助你解决这样的问题,而不必问问题和等待答案……

你需要小心使用gmail作为smtp服务器中继@Hackerman我没有超过限制的错误。它的smtp失败了