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.'; }
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With