这是我的php
脚本:
<?php
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('../class.phpmailer.php');
include("../class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // 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; // or 587
$mail->IsHTML(true);
$mail->Username = "x@gmail.com";
$mail->Password = "1234";
$mail->From = "y@gmail.com";
$mail->Subject = "Need Invitation";
$mail->Body = "invite me!";
$mail->AddAddress("x@gmail.com");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
执行此脚本后,我收到以下错误:
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (1)
我还启用了ssl
:
有很多问题与此非常相似,但没有得到任何帮助。
答案 0 :(得分:0)
尝试更改
$mail->Host = "ssl://smtp.gmail.com";
到
$mail->Host = "smtp.gmail.com";
SSL在HTTP,SMTP等网络模型中的运行级别不同。
您可能还需要将SMTPSecure
设置从'ssl'
更改为'tls'
。