0

我正在尝试使用 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 转发并打开此页面 https://accounts.google.com/DisplayUnlockCaptcha 单击继续并刷新要发送的页面,但它不起作用我收到邮件错误: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)';
}
}
?>

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

4

1 回答 1

1

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

于 2013-11-07T22:59:07.273 回答