0

I am trying to send mail through PHP Mailer and i have got a error like this

Error:

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

 ?>

Can anyone help me to figure out what is happening here. ? Thanks

Madhi
  • 45
  • 1
  • 12

2 Answers2

0

You missed this variable :

$mail->SMTPSecure = "tls";

OR

 $mail->SMTPSecure = "ssl";

Try one of them.

prakash tank
  • 1,269
  • 1
  • 9
  • 15
  • i tried,...but still there is an error....anyways thanks for your answer.. :) @prakashtank – Madhi Dec 21 '16 at 07:40
  • check this : http://stackoverflow.com/questions/3477766/phpmailer-smtp-error-could-not-connect-to-smtp-host – prakash tank Dec 21 '16 at 07:42
  • Have you checked used gmail account settings? https://www.wpsitecare.com/gmail-smtp-settings/ Please check once. – Jyoti mishra Dec 21 '16 at 08:09
  • i edited my post just now..and i have following errors which i have mentioned above..help me to correct those errors..thanks.. – Madhi Dec 21 '16 at 08:31
0

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.

From the error message you can see exactly what the problem is - while you have set Username and Password properties, you have disabled authentication. Enable it like this.

$mail->SMTPAuth = true;

You're also using an old version of PHPMailer, so get the latest.

Synchro
  • 35,538
  • 15
  • 81
  • 104