以下发件人地址未通过连接调用Mail()失败

以下发件人地址未通过连接调用Mail()失败

问题描述:

Hello guys I get this error:

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";
}
?>

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

大家好我得到这个错误: p>

以下地址失败:username_from@gmail.com:调用Mail()而未连接 p> blockquote>

 &lt;?php 
require(“PHPMailer / class。  phpmailer.php“); 
 
 $ msg ='hello world!'; 
 
 $ mail = new PHPMailer(); 
 $ mail-&gt; IsSMTP(); 
 $ mail-&gt; Host  ='smtp.gmail.com'; 
 $ mail-&gt;端口= 465; 
 $ mail-&gt; SMTPAuth = true; 
 $ mail-&gt;用户名='username@gmail.com'; 
  $ mail-&gt;密码='密码'; 
 $ mail-&gt; SMTPSecure ='ssl'; 
 $ mail-&gt; From ='username_from@gmail.com'; 
 $ mail-&gt; FromName =  '我的名字'; 
 $ mail-&gt; AddAddress('other_user@gmail.com',''); 
 $ mail-&gt; WordWrap = 50; 
 $ mail-&gt; IsHTML(true); \  n $ mail-&gt; Subject ='hello'; 
 $ mail-&gt; Body = $ msg; 
 
if(!$ mail-&gt; Send()){
 echo“Mailer Error:”。  $ mail-&gt; ErrorInfo; 
} 
else {
 echo“消息已发送”; 
} 
?&gt; 
  code>  pre> 
 
 

怎么能 我修理它? 谢谢! 我使用Gmail邮件服务器从运行XAMPP的localhost发送电子邮件。 p> div>

Possible reason for error:

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

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

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

  • You don't need to call singleTo if you're only adding one address anyway.
  • Try and set Host to smtp.gmail.com
  • you can add $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only so you can see some debug statements?