Getting Mailer Error: SMTP connect() failed error while sending email


I am using Phpmailer to send emails. THe below code works fine in local but it is not in 000webhost.

require 'PHPMailer/PHPMailerAutoload.php';	
include ("db.php");
$mail = new PHPMailer;

$mail->Host = ';'; 
$mail->SMTPAuth = true;                               
$mail->Username = '';
$mail->Password = 'password';                    
$mail->SMTPSecure = 'tls';                           
$mail->Port = 587;                                    

$mail->setFrom('', 'Example');
$mail->addAddress('', 'Manikandan');
if($mail->IsError()) die($mail->ErrorInfo);
$mail->Subject = 'Email subjects';
$mail->Body    = 'Hello Sir, <br>Pleasse find the attachment...<br><br><br><br>Thanks';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';

I remember i have made some changes in php.ini in local but i am not able to find it here… Iam new to this.Any help will be appriciated.


Have a look at this troubleshooting guide.

Since you are using Gmail, you probably need to turn on the “Allow less secure apps” switch in your Google security settings.

Incidentally, please don’t ask for “immediate” help on the web - read this discussion to understand why. A number of folks here are volunteers, and they will answer you at their leisure :slight_smile:


halfer sorry for asking immediate help :slight_smile: and I tried your suggestion still i am facing the same problem.


Are there any errors that are thrown?
If no errors are shown, try this tutorial, maybe some errors aren’t thrown