SMTP connect() failed PHPmailer - PHP
You need to add the Host
parameter
$mail->Host = "ssl://smtp.gmail.com";
Also, check if you have open_ssl
enabled.
<?php
echo !extension_loaded('openssl')?"Not Available":"Available";
PHPMailer SMTP connection failed error
You are getting a DNS error that says it can’t find the host name. So look at your host name property, and see it contains smtp1.gmail.com
when it should be smtp.gmail.com
.
Fatal error: Uncaught phpmailerException: SMTP connect() failed
Several straightforward errors.
Firstly you're using a very old version of PHPMailer. Upgrade, and ideally switch to using composer.
One simple typo: $mail->SMTPSecure = 'tsl';
should be $mail->SMTPSecure = 'tls';
.
Next is a bit more conceptual - you can't get a valid certificate (signed by a public CA) for localhost
, so you'll always have trouble trying to do that. There's no benefit in using an encrypted connection to localhost anyway because nothing travels over a network. It's also likely that you don't need authentication when submitting to localhost.
I'd recommend changing all this:
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->SMTPDebug = 4;
$mail->Username = 'seushms@gmail.com'; // SMTP false username
$mail->Password = ''; // SMTP false password
$mail->SMTPSecure = 'tsl'; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
to just this, because everything else will work with defaults:
$mail->isSMTP();
smtp connect() failed in PHP using phpmailer Library
Hey Do you Allow less secure apps to access your Gmail account
?
if you not allow less secure apps enable and Run again and see the result.
Here is the Example:
https://devanswers.co/allow-less-secure-apps-access-gmail-account/
SMTP connect() failed phpmailer
You should really read what the troubleshooting guide says - that's why the link to it is included in the error output. Set SMTPDebug = 2
so you can see what the server says and it will probably tell you what's wrong.
Related Topics
Best Way to Completely Destroy a Session - Even If the Browser Is Not Closed
Login Without Https, How to Secure
Error 330 (Net::Err_Content_Decoding_Failed):
Laravel 5 - Clear Cache in Shared Hosting Server
How to Best Configure PHP to Handle a Utf-8 Website
Decode Gzipped Web Page Retrieved Via Curl in PHP
Insert Query on Page Load, Inserts Twice
Stop People Uploading Malicious PHP Files Via Forms
How to Get Response Using Curl in PHP
Running Command-Line Application from PHP as Specific User
Super Fast Getimagesize in PHP
Compare Multiple Values in PHP
Elegant Way to Get the Count of Months Between Two Dates