Madhi
Madhi

Reputation: 45

sending mail through PHPMailer

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 [email protected] : 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

Upvotes: 0

Views: 1398

Answers (2)

Synchro
Synchro

Reputation: 37810

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.

Upvotes: 0

prakash tank
prakash tank

Reputation: 1267

You missed this variable :

$mail->SMTPSecure = "tls";

OR

 $mail->SMTPSecure = "ssl";

Try one of them.

Upvotes: 0

Related Questions