2

我已经阅读了网络上的每个示例,但我似乎仍然无法连接到 GMAIL SMTP。这是我正在运行的代码:

include("phpMailer/class.phpmailer.php"); // path to the PHPMailer class
$mail = new PHPMailer(); 
$mail->IsSMTP(); // send via SMTP

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myUsername"; // SMTP username
$mail->Password = "myPassword"; // SMTP password
$mail->SMTPDebug = 1;
$webmaster_email = "webMasterEmail@gmail.com"; //Reply to this email ID
$email="someone@gmail.com"; // Recipients email ID
$name="SomeonesName"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Me";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
    echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
    echo "Message has been sent";
}

我尝试在此处设置端口,并且我还在 class.smtp.php 文件中使用以下内容进行了当前设置:

$host = "ssl://smtp.gmail.com";
$port = 465;

我不断收到相同的错误,并且已确保启用了 ssl。我得到的错误是:

SMTP -> ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it.(10061)
4

1 回答 1

1

正如我上面提到的,我已经通过摆脱 ; 来启用 ssl。与 php_openssl.dll 并重新启动 Apache 就行了。我做了更多阅读,发现有些人在启用命令之前也有“[PHP_OPENSSL]”。我添加了它并重新启动了 Apache,一切正常!感谢所有的评论

在 php.ini 中:

[PHP_OPENSSL]
extension=php_openssl.dll
于 2012-07-04T14:41:31.693 回答