Authentication error when signing up “PHPMailerPHPMailerException: SMTP Error: Could not authenticate. in”

# ...

if (...) {
  try {
    # ...

    $mail->SMTPSecure = $flag ? PHPMailer::ENCRYPTION_SMTPS : PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port = $general->email_config->smtp_port;
    $mail->CharSet = 'UTF-8';
    $mail->setFrom($general->site_email, $general->sitename);
    $mail->addAddress($data['email']);
    $mail->addReplyTo($general->site_email, $general->sitename);
    $mail->isHTML(true);
    $mail->Subject = $data['subject'];
    $mail->Body = $data['message'];
    $mail->send();
  } catch (Exception $e) {
    throw new Exception($e, 0, $e);
  }

  return redirect()->route('user.authentication.verify');
} elseif ($general->is_sms_verification_on && !$user->sv) {
  $calling_code = rtrim(file_get_contents('https://ipapi.co/103.100.232.0/country_calling_code/'), "0");

  $pseudoRandomNumber = rand(0, 999999);  
  $user->sms_verification_code = $pseudoRandomNumber;
  $user->save();

  try {
    $basic = new NexmoClientCredentialsBasic(env("NEXMO_KEY"), 
    env("NEXMO_SECRET"));
    $client = new NexmoClient($basic);

    # ...

Authentication error while trying to sign up and it shows 500 internal server error.

Tried to backdate the website but error did not change.