Phpmailer failing smtp authentication using gmail


I am able to send emails using phpmailer and gmail when my website is hosted on my local WAMP stack. This means that I’ve configured my gmail account correctly and am using the correct phpmailer parameters to send emails.

When I moved my site to my infinityfree account, phpmailer is indicating that its failing authentication.
So I turned ON SMTP debuging to get a more verbose error. Here it is:

2019-05-24 05:19:04 SERVER -> CLIENT: 534-5.7.14 SMTP ERROR: Password command failed: Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14
SMTP Error: Could not authenticate.

Here is the relevant PHP code that calls phpmailer:

$mail = new PHPMailer(true);

try {

    $mail->isSMTP();                                            // Set mailer to use SMTP
    $mail->SMTPDebug = 2;
    //Server settings
    $mail->Host       = '';  // Specify main and backup SMTP servers
    $mail->Port       = 587;                                    // TCP port to connect to
    $mail->SMTPSecure = 'tls';                                  // Enable TLS encryption, `ssl` also accepted
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = '[email protected]';                     // SMTP username
    $mail->Password   = 'xxxx';                               // SMTP password

    $mail->setFrom('[email protected]', 'Joselito');
    $mail->addAddress($toEmail, 'Joe User');     // Add a recipient

    // Content
    $mail->Subject = $emailSubject;
    $mail->Body    = $emailContent;
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";

Again, this all works in my local WAMP stack. Is there something more to be configured in order to get this working on infinityfree and the gmail SMTP smtp server?

Thanks in advance for your help.


Thanks, OxyDac, for responding, but I’ve already set my google email account to allow for ‘less secure apps’ as per your suggestion yet the problem remains when I upload my site to

As I mentioned, I’m able to send emails from my local WAMP stack, but not on

Any further suggestions I can try? I’m getting the same behavior when I used the hotmail smtp server.


If you were using the Outlook SMTP server, you want to make sure that the PHPMailer is configured to use the Hotmail/Outlook mail.
Then configure the SMTP like this:
SMTP server: tls://
Port: 587
Security method: TLS
Use authentication, then put your Outlook email and password.

If you are using the Gmail SMTP server, you need to go to enable Less Secure Apps, then toggle the CAPTCHA request on login (change the password after doing so!) and enable Gmail SMTP from your Gmail. Then use these details:
SMTP server: tls://
Port: 587
Security method: TLS
Use authentication, then put your Google ID (AKA your Gmail mail) and password.

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