以下“发件人"地址失败,但未连接,但调用了Mail() [英] The following From address failed Called Mail() without being connected

查看:149
本文介绍了以下“发件人"地址失败,但未连接,但调用了Mail()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我收到此错误:

Hello guys I get this error:

以下发件人地址失败:username_from@gmail.com:未连接就调用Mail()

The following From address failed: username_from@gmail.com : Called Mail() without being connected

<?php
require("PHPMailer/class.phpmailer.php");

$msg = 'hello world!';

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'username@gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->From = 'username_from@gmail.com';
$mail->FromName = 'My name';
$mail->AddAddress('other_user@gmail.com', '');
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = 'hello';
$mail->Body = $msg;

if(!$mail->Send()){
    echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
    echo "Message has been sent";
}
?>

我该如何解决?谢谢!我使用Gmail邮件服务器从在PHP中运行XAMPP的本地主机发送电子邮件.

How can I fix it? Thanks! I send email from localhost running XAMPP in PHP using Gmail mail server.

推荐答案

可能的错误原因:

  • 您必须编辑您的gmail帐户权限.尝试启用访问不太安全的应用程序"的安全性"设置.

  • you have to edit your gmail account permissions. Trying enabling the 'Access for less secure apps' Security setting.

可能是,您正在使用旧版本的PHPMailer-更新它.

may be,you're using an old version of PHPMailer - update it.

请勿将ssl/465用于gmail;使用tls/587.看看 gmail示例代码与PHPMailer一起提供.

Don't use ssl/465 for gmail; use tls/587. Take a look at the gmail example code provided with PHPMailer.

这篇关于以下“发件人"地址失败,但未连接,但调用了Mail()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆