0

I tried to create a mail-confirm signup system but when I signup, database save my data but there is a error that says:

SMTP Error: Could not authenticate.

note: I am using class.phpmailer.php

I could not understand the problem. Here is my code:

sendmail.php

<?php
require 'PHPMailerAutoload.php';

function send_mail($sendto, $subject, $body)
{

    $mail = new PHPMailer;

//$mail->SMTPDebug = 2;                               // Enable verbose debug output

    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '**.****.****@gmail.com';                 // SMTP username
    $mail->Password = '**********';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to

    $mail->setFrom('e.d***.c**@gmail.com', 'Restro | Restaurants in Mumbai');
    $mail->addAddress($sendto);               // Name is optional
    $mail->addReplyTo('e.d****.c***@gmail.com', 'Restro | Restaurants in Mumbai');

    $mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AltBody = 'Please open this on Chrome';

    if (!$mail->send()) {
        //echo 'Message could not be sent.';
        return 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        return 'Message has been sent';
    }
}
Jack Niv
  • 15
  • 3
  • Does this answer your question? [Unable to send email using Gmail SMTP server through PHPMailer, getting error: SMTP AUTH is required for message submission on port 587. How to fix?](https://stackoverflow.com/questions/16048347/unable-to-send-email-using-gmail-smtp-server-through-phpmailer-getting-error-s) – Dhaval Purohit Mar 06 '20 at 11:02

1 Answers1

0

Use port 465

port 587 if your client begins with plain text before issuing the STARTTLS command.