phpmailer无法连接到SMTP [英] phpmailer Could not connect to SMTP

查看:122
本文介绍了phpmailer无法连接到SMTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此消息,但我不知道问题出在哪里. 在我的php.ini中,我没有注释具有extension = php_openssl.dll的行,但是它仍然无法正常工作.欢迎任何建议.

Hi i am getting this message i dont know where is the problem. In my php.ini i have uncommented the line with extension=php_openssl.dll but it still not working. Any advice is welcome.

无法发送邮件.邮件程序错误:SMTP错误:无法连接到SMTP主机.

Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host.

<?php
require 'class.phpmailer.php';

$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';                 // Specify main and backup server
$mail->Port = 465;                                    // Set the SMTP port
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'mattoni.resta.test@gmail.com';                // SMTP username
$mail->Password = 'mattonirestaurace';                  // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'mattoni.resta.test@gmail.com';
$mail->FromName = 'Your From name';
$mail->AddAddress('josh@example.net', 'Josh Adams');  // Add a recipient
$mail->AddAddress('ellen@example.com');               // Name is optional

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

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent';
?>

推荐答案

实际上,您的代码是正确的.您必须更改gmail ..中的设置.

actually, your code is correct.thing is you've to change settings in gmail..!

这篇关于phpmailer无法连接到SMTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆