我正在使用PHPMailer库
我想用雅虎发送电子邮件到Gmail
以下是我尝试的代码:
testemail.php
<?php
require_once('./PHPMailer-master/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.mail.yahoo.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'testllk@yahoo.com';
$mail->Password = 'a1b2c3d4e5';
$mail->SMTPSecure = 'ssl';
$from = $mail->Username;
$fromName = 'llktest';
$toList = 'testllk@gmail.com';
$subject = 'PHPMailer test';
$body = 'Hi, everyone.<br />';
$body .= 'I am performing <i>PHPMailer test</i>.';
$mail->SetFrom($from, $fromName);
$mail->AddReplyTo($from, $fromName);
foreach($toList as $to)
{
$mail->AddAddress($to);
}
$mail->Subject=$subject;
$mail->MsgHTML($body);
if(!$mail->Send())
{
echo 'Mailer Error: '.$mail->ErrorInfo;
}
else
{
echo 'Message sent!';
}
?>
在我编写上述代码后,我创建了一个新的yahoo帐户(testllk@yahoo.com)
在我创建一个雅虎帐户后,我在网页上运行testemail.php。
但是,我收到以下错误:
Mailer Error: SMTP connect() failed.
为什么我无法发送电子邮件?
我的编码问题或雅虎设置问题?
有什么想法吗?