简体   繁体   English

通过PHPMailer发送邮件

[英]sending mail through PHPMailer

I am trying to send mail through PHP Mailer and i have got a error like this 我正在尝试通过PHP Mailer发送邮件,但出现了这样的错误

Error: 错误:

SMTP ERROR: MAIL FROM command failed: 530-5.5.1 Authentication Required. SMTP错误:MAIL FROM命令失败:530-5.5.1需要身份验证。 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. 了解更多信息at530 5.5.1 https://support.google.com/mail/?p=WantAuthError s8sm44466998pfj.45-gsmtp以下发件人地址失败:我的电子邮件地址@ gmail.com:MAIL FROM命令失败,需要身份验证。 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. 有关更多信息, 访问https://support.google.com/mail/?p=WantAuthError s8sm44466998pfj.45-gsmtp,530,5.5.1SMTP服务器错误:MAIL FROM命令失败详细信息:需要身份验证。 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>";
   }

 ?>

Can anyone help me to figure out what is happening here. 谁能帮我弄清楚这里发生了什么。 ? Thanks 谢谢

You missed this variable : 您错过了此变量:

$mail->SMTPSecure = "tls";

OR 要么

 $mail->SMTPSecure = "ssl";

Try one of them. 尝试其中之一。

Don't just add random stuff to your code in the hope that it will help! 不要只是将随机的东西添加到您的代码中,希望对您有所帮助! The only one of those requires you need is the autoloader. 其中唯一需要的就是自动装带器。 Base your code on the gmail example provided with PHPMailer , or at least the basic example provided in the readme. 您的代码基于PHPMailer附带的gmail示例 ,或者至少自述文件中提供的基本示例。

From the error message you can see exactly what the problem is - while you have set Username and Password properties, you have disabled authentication. 从错误消息中,您可以确切地了解问题所在-设置UsernamePassword属性后,您已禁用身份验证。 Enable it like this. 这样启用它。

$mail->SMTPAuth = true;

You're also using an old version of PHPMailer, so get the latest . 您还使用了旧版本的PHPMailer,因此请获取最新版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM