PHP邮件程序在localhost中工作,但在服务器中显示以下错误

PHPmailer error on my website

I tried all the solutions given to questions similar to mine (allowed less secured apps, display captcha, using 465 port for ssl, etc).

Can anyone tell if I have to change any settings on cpanel to send mails using gmail?

I remove below line from localhost code and it worked.

define("MAILER", "smtp");

Above line is not required and causing the error