google phpmailer错误SMTP错误:无法连接到SMTP主机

google phpmailer错误SMTP错误:无法连接到SMTP主机,php,smtp,phpmailer,Php,Smtp,Phpmailer,我正在尝试使用google php mailer,但我收到了很多错误消息。我已上载一份新副本以再次测试,但出现以下错误: SMTP Error: Could not connect to SMTP host 调试之后,我收到了这个消息 SMTP -> ERROR: Failed to connect to server: Network is unreachable (101) SMTP Error: Could not connect to SMTP host 我已从gmail启用

我正在尝试使用google php mailer,但我收到了很多错误消息。我已上载一份新副本以再次测试,但出现以下错误:

SMTP Error: Could not connect to SMTP host
调试之后,我收到了这个消息

SMTP -> ERROR: Failed to connect to server: Network is unreachable (101) 
SMTP Error: Could not connect to SMTP host
我已从gmail启用IMAP和POP转发,并打开了此页面 单击“继续”并刷新要从中发送的页面,但该页面不工作。我收到邮件错误:SMTP Connect()失败

代码如下:

<?php
require_once('class.phpmailer.php');
define('GUSER', 'username@gmail.com'); // GMail username
define('GPWD', 'password'); // GMail password
function smtpmailer($to, $from, $from_name, $subject, $body) { 
global $error;
$mail = new PHPMailer();  // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0;  // 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; 
$mail->Username = GUSER;  
$mail->Password = GPWD;           
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
    $error = 'Mail error: '.$mail->ErrorInfo; 
    return false;
} else {
    $error = 'Message sent!';
    return true;
}
}

$msg = 'Hello World';
$subj = 'test mail message';
$to = 'username@yahoo.com';
$from = 'username@gmail.com';
$name = 'any name';

if (smtpmailer($to, $from, $name, $subj, $msg)) {
echo 'Yippie, message send via Gmail';
} else {
if (!smtpmailer($to, $from, $name, $subj, $msg, false)) {
    if (!empty($error)) echo $error;
} else {
    echo 'Yep, the message is send (after doing some hard work)';
}
}
?>


如何解决这个问题?提前感谢

检查服务器上的php.ini文件。验证openssl.dll行是否未注释

是否尝试了端口25?请尝试$mail->Host=ssl://smtp.gmail.com';将端口更改为25不起作用,并且ssl://smtp.gmail.com 上载文件的另一个副本后无法工作我收到以下错误:SMTP错误:无法连接到SMTP主机