0

I am trying to send SMTP email using below php code.

    <?php

require_once "Mail.php";


$from = "info@XXXXX.com";
$to = "info@XXXXXX.com";
$subject = "Hi";
$body = "Hi,\n\nHow are you?\nDoing anything this Friday evening?\n";

 $host = "ssl://smtp.gmail.com";
 $port = "465";
$username = "xxxxx";
$password = "xxxxx";

$headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);

 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'port' => $port,
     'auth' => true,
     'username' => $username,
     'password' => $password)); 

$mail = $smtp->send( $to, $headers, $body );

if ( PEAR::isError($mail) ) {
echo( "<p>" . $mail->getMessage() . "</p>" );
} else {
echo( "<p>Message successfully sent!</p>" );
}

 ?>

While i am executing the code from unix webserver webpage. I am getting following error.

authentication failure [SMTP: Invalid response code received from server (code: 535, response: Incorrect authentication data)]

But the above code working fine in my localhost.

Please help me to finish the project.

Thanks.

1 Answers1

-1

I had the same problem, you should enable SMTP in G-Suite, more details here: https://support.google.com/a/answer/2956491?hl=en

metodi25
  • 25
  • 7