Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMTP Connect() failed. Message was not sent.Mailer error: SMTP Connect() failed

Tags:

php

email

smtp

Am trying to send mail to a gmail address but it keeps on getting this error "SMTP -> ERROR: Failed to connect to server: Connection timed out (110)SMTP Connect() failed. Message was not sent.Mailer error: SMTP Connect() failed." What could be the problem?

        require 'class.phpmailer.php'; // path to the PHPMailer class         require 'class.smtp.php';              $mail = new PHPMailer();               $mail->IsSMTP();  // telling the class to use SMTP             $mail->SMTPDebug = 2;             $mail->Mailer = "smtp";             $mail->Host = "ssl://smtp.gmail.com";             $mail->Port = 587;             $mail->SMTPAuth = true; // turn on SMTP authentication             $mail->Username = "[email protected]"; // SMTP username             $mail->Password = "mypasswword"; // SMTP password              $Mail->Priority = 1;              $mail->AddAddress("[email protected]","Name");             $mail->SetFrom($visitor_email, $name);             $mail->AddReplyTo($visitor_email,$name);              $mail->Subject  = "Message from  Contact form";             $mail->Body     = $user_message;             $mail->WordWrap = 50;                if(!$mail->Send()) {             echo 'Message was not sent.';             echo 'Mailer error: ' . $mail->ErrorInfo;             } else {             echo 'Message has been sent.';             } 
like image 670
Muli Avatar asked Aug 28 '13 19:08

Muli


People also ask

How do I enable SMTP in Gmail?

Set up the app or device with the Gmail SMTP serverOn your device or in the app, enter smtp.gmail.com as the server address. In the Port field, enter one of the following numbers: If you're using SSL, enter 465. If you're using TLS, enter 587.

Could not authenticate mailer error SMTP error could not authenticate?

Error: SMTP error: could not authenticateThis error indicates that the client could not authenticate with the email server. It can be the cause of multiple reasons, for example: The user did not enter valid credentials when logging in. The user did not verify with the multi-factor authentication mechanisms enabled.

Can't connect to Gmail SMTP host?

By default, gmail does not allow connections from third party software. If the option “access for less secure apps” is not enabled in the gmail account, users get the error “Unable to connect to SMTP host” in their websites.


1 Answers

Remove or comment out the line-

$mail->IsSMTP(); 

And it will work for you.

I have checked and experimented many answers from different sites but haven't got any solution except the above solution.

like image 194
Snehasis Avatar answered Sep 22 '22 23:09

Snehasis