通过 PHPMailer 发送邮件

sending mail through PHPMailer

我正在尝试通过 PHP Mailer 发送邮件,但我遇到了这样的错误

错误:

SMTP ERROR: MAIL FROM command failed: 530-5.5.1 Authentication Required. Learn more at530 5.5.1 https://support.google.com/mail/?p=WantAuthError s8sm44466998pfj.45 - gsmtp The following From address failed:my email address@gmail.com : MAIL FROM command failed,Authentication Required. Learn more at https://support.google.com/mail/?p=WantAuthError s8sm44466998pfj.45 - gsmtp,530,5.5.1SMTP server error: MAIL FROM command failed Detail: Authentication Required. Learn more at Message cannot be send

   <?php

require_once ('PHPMailer-master/class.pop3.php');
require_once ('PHPMailer-master/class.smtp.php');
require_once ("PHPMailer-master/class.phpmailer.php");
require_once ("PHPMailer-master/PHPMailerAutoload.php");
   $mail = new PHPMailer();
   $mail->isSMTP();
   $mail->Host = "smtp.gmail.com";
   $mail->SMTPAuth = false;
   $mail->SMTPDebug =1;
   $mail->Debugoutput = 'html';
   $mail->Port = 587;
   $mail->SMTPSecure = 'tls';
   $mail->Username = "my email address";
   $mail->Password = "email password";
   $mail->setFrom("email address","name");
   $mail->addAddress("my friend email address");
   $mail->Subject = 'First Mailer in Php';
   $mail->Body= 'this is first mail...sending through php code';
   if(!$mail->send()){
       echo "Message cannot be send"."<br/>";
       echo "MailerError".$mail->ErrorInfo;
       exit;
   }else{
       echo "<script>window.alert('Message has been sent');</script>";
   }

 ?>

谁能帮我弄清楚这里发生了什么。 ?谢谢

您错过了这个变量:

$mail->SMTPSecure = "tls";

 $mail->SMTPSecure = "ssl";

尝试其中之一。

不要只是在代码中随意添加一些东西,希望它能有所帮助!您唯一需要的要求是自动加载器。您的代码基于 the gmail example provided with PHPMailer,或者至少基于自述文件中提供的基本示例。

从错误消息中您可以准确地看出问题所在 - 当您设置了 UsernamePassword 属性时,您已禁用身份验证。像这样启用它。

$mail->SMTPAuth = true;

您还在使用旧版本的 PHPMailer,所以 get the latest