1

I have configured phpmailer for my wordpress site following way:

<?php
add_action( 'phpmailer_init', 'setup_smtp');
function setup_smtp( $phpmailer ) {
    if ( ! is_object( $phpmailer ) ) {
        $phpmailer = (object) $phpmailer;
    }
    
    $phpmailer->Mailer     = 'smtp';
    $phpmailer->Host       = 'smtp.gmail.com';
    $phpmailer->SMTPAuth   = true;
    $phpmailer->Port       = '465';
    $phpmailer->Username   = 'duet383@gmail.com';
    $phpmailer->Password   = 'xxxxxxxx';
    $phpmailer->SMTPSecure = 'ssl';
    $phpmailer->From       = 'duet383@gmail.com';
    $phpmailer->FromName   = 'Asian Restaurant';
    $phpmailer->SMTPDebug   = 2;

}

It is sending email when it is on localhost but when on real server it is giving following error:

2021-05-05 17:28:55 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP 26sm5525488qtd.73 - gsmtp
2021-05-05 17:28:55 CLIENT -> SERVER: EHLO miraj94.000webhostapp.com
2021-05-05 17:28:55 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2a02:4780:bad:3:fced:1ff:fe03:76]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2021-05-05 17:28:55 CLIENT -> SERVER: AUTH LOGIN
2021-05-05 17:28:55 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2021-05-05 17:28:55 CLIENT -> SERVER: [credentials hidden]
2021-05-05 17:28:55 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2021-05-05 17:28:55 CLIENT -> SERVER: [credentials hidden]
2021-05-05 17:28:56 SERVER -> CLIENT: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu534-5.7.14 mBCp0KPnA6lLVDXtO3PD4WNqyB_meMsjJFlkSNZ9vC63f-RVlCMCuQTTtGyTG_O-Udkkr534-5.7.14 ll7IKMM31GmIn6raNGiiVq6cQEREBB9fClbMYCyhqBphXb93cJjmcAqwJXJw0QxJ>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 26sm5525488qtd.73 - gsmtp
2021-05-05 17:28:56 SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu534-5.7.14 mBCp0KPnA6lLVDXtO3PD4WNqyB_meMsjJFlkSNZ9vC63f-RVlCMCuQTTtGyTG_O-Udkkr534-5.7.14 ll7IKMM31GmIn6raNGiiVq6cQEREBB9fClbMYCyhqBphXb93cJjmcAqwJXJw0QxJ>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 26sm5525488qtd.73 - gsmtp
SMTP Error: Could not authenticate.
2021-05-05 17:28:56 CLIENT -> SERVER: QUIT
2021-05-05 17:28:56 SERVER -> CLIENT: 221 2.0.0 closing connection 26sm5525488qtd.73 - gsmtp
SMTP Error: Could not authenticate.

I am using free web hosting and domain on 000webhost.com and my site address is https://miraj94.000webhostapp.com

Mirajul Momin
  • 157
  • 1
  • 17
  • 2
    Have you considered reading the error message, when it says things like "Please log in via your web browser and then try again", and then gives you some links to follow, or searching for that error message which will lead you to the [many questions that have been asked about it here](https://stackoverflow.com/search?q=phpmailer+log+in+via+your+web+browser), and the PHPMailer docs that cover [this exact issue](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#gmail-oauth2-and-allow-less-secure-apps) in great detail? `Port` should be an int, not a string. – Synchro May 05 '21 at 18:08

2 Answers2

1

After long study I found a solution.

  1. Login to my Gmail account
  2. Go to https://accounts.google.com/b/0/DisplayUnlockCaptcha
  3. Click on continue button
    [Less secure app access was already enabled]

Additionally this stackoverflow answer maybe helpful.

Mirajul Momin
  • 157
  • 1
  • 17
0

Free plan does not support email accounts.
https://www.000webhost.com/
if you want to send emails from your website change your hosting or upgrade to paid plan

anzepintar
  • 126
  • 1
  • 10