Php mailer cant send email

Hello, I am trying to host my website that has a signup Gmail verification using PHP mailer. My code is working fine on localhost but when I host it here my code does not work anymore.

Here is my code:
require ‘php/PHPMailer.php’;
require ‘php/SMTP.php’;
require ‘php/Exception.php’;

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

$mail = new PHPMailer;
$mail->Host = “smtp.gmail.com”;
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = ‘tls’;
$mail->isHTML(true);

$mail->Username = “[email protected]”;
$mail->Password = ‘mypass’;

$mail->setFrom(‘[email protected]’,‘AraLink’);
$mail->addAddress($email);
$mail->Subject=‘Email Verification Code’;
$mail->Body=“Your verification code is $code”;

Thank you!

Update I added $mail->isSMTP(); to my code and it gives me SMTP connect() failed. Troubleshooting · PHPMailer/PHPMailer Wiki · GitHub;

Maybe this should help?

The problem can likely be solved by completing the steps below.

Do this:

  1. Turn on “Less Secure Apps” in your Google Account settings

  2. Turn on 2Fa (Two Factor Authorization) on your account

  3. Generate an app password (Under the Privacy tab in your Google Account Settings) and use that instead of your normal password

3 Likes

Please see this article from two days ago, the situation seems exactly the same:

2 Likes

Thank you! Its now working

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.