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 = "myemail@gmail.com"; // SMTP username
$mail->Password = "mypasswword"; // SMTP password
$Mail->Priority = 1;
$mail->AddAddress("myemail@gmail.com","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.';
}
AnFi
10.4k3 gold badges23 silver badges47 bronze badges
asked Aug 28, 2013 at 19:29
4
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.
dario
5,12912 gold badges28 silver badges32 bronze badges
answered Aug 10, 2015 at 12:51
SnehasisSnehasis
9156 silver badges10 bronze badges
17
You must to have installed php_openssl.dll, if you use wampserver it’s pretty easy, search and apply the extension for PHP.
In the example change this:
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission 465 ssl
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
and then you recived an email from gmail talking about to enable the option to Less Safe Access Applications
here https://www.google.com/settings/security/lesssecureapps
I recommend you change the password and encrypt it constantly
answered Oct 8, 2014 at 2:03
El DavidEl David
6168 silver badges17 bronze badges
1
You’ve got no SMTPSecure setting to define the type of authentication being used, and you’re running the Host setting with the unnecessary ‘ssl://’ (PS — ssl is over port 465, if you need to run it over ssl instead, see the accepted answer here. Here’s the lines to add/change:
+ $mail->SMTPSecure = 'tls';
- $mail->Host = "ssl://smtp.gmail.com";
+ $mail->Host = "smtp.gmail.com";
answered Aug 29, 2013 at 20:58
Dmitri DBDmitri DB
3173 silver badges15 bronze badges
4
Are you running on Localhost? and have you edit the php.ini
?
If not yet, try this:
1. Open xampp->php->php.ini
2. Search for extension=php_openssl.dll
3. The initial will look like this ;extension=php_openssl.dll
4. Remove the ‘;’ and it will look like this extension=php_openssl.dll
5. If you can’t find the extension=php_openssl.dll
, add this line extension=php_openssl.dll
.
6. Then restart your Xampp.
Goodluck
answered Jan 11, 2014 at 4:03
1
I know its been a while since this question but I had the exact problem and solved it by disabling SMTP_BLOCK on csf.conf (we use CSF for a firewall).
To disable just edit csf.conf and disable SMTP_BLOCK like so:
###############################################################################
# SECTION:SMTP Settings
###############################################################################
# Block outgoing SMTP except for root, exim and mailman (forces scripts/users
# to use the exim/sendmail binary instead of sockets access). This replaces the
# protection as WHM > Tweak Settings > SMTP Tweaks
#
# This option uses the iptables ipt_owner/xt_owner module and must be loaded
# for it to work. It may not be available on some VPS platforms
#
# Note: Run /etc/csf/csftest.pl to check whether this option will function on
# this server
# SMTP_BLOCK = "1" --> this will cause phpmailer Connection timed out (110)
SMTP_BLOCK = "0"
answered Jan 23, 2016 at 20:32
GoldbugGoldbug
6076 silver badges8 bronze badges
1
i’ve had this problem in tell i recive an email from google telling me that someone try to login to your account is it you and i answer yes then it start workin so if this is the case for you look in your email and allow the server
answered Jul 16, 2016 at 12:59
2
Login your Google account at myaccount.google.com/security go to «Login» and then «Security», scroll to bottom then enable the «Allow less secure apps» option.
Daniel
1,22914 silver badges24 bronze badges
answered Dec 27, 2016 at 22:07
Here is a list of this you should look into when dealing with PHPMailer:
- Enable openSSL by un-commenting
extension=php_openssl.dll
in your PHP.ini - Use
$mail->SMTPSecure = 'tls';
and$mail->Port = 587;
- Enable debugging for if you are going wrong somewhere else like incorrect username and password etc.
answered May 14, 2015 at 7:02
KKKKKK
3,1595 gold badges35 silver badges58 bronze badges
You are doing all well. Just you have to check different SMTP ports like 465 and others that works on your system.
Another thing to keep in mind to allow access to the less secure apps by google account otherwise it throws the same error.
I have gone through it for a whole day and the only thing I am doing wrong is the port no., I just changed the port no. and it works.
answered Mar 7, 2017 at 13:59
Deepak KumarDeepak Kumar
6771 gold badge8 silver badges22 bronze badges
Mailjet
SMTP SETTINGS
Port: 25 or 587 (some providers block port 25)
I work by changing the port after deploying the app to the server.
- In Debug it worked for me:
$mail->Port = 25;
- In Release it worked for me:
$mail->Port = 587;
GL
answered Dec 19, 2018 at 2:13
Braian CoronelBraian Coronel
21.9k4 gold badges56 silver badges60 bronze badges
To get it working, I had to go to myaccount.google.com -> «connected apps & sites», and turn «Allow less secure apps» to «ON» (near the bottom of the page).
answered Aug 1, 2017 at 9:19
If it works on your localhost but not on your web host:
Some hosting sites block certain outbound SMTP ports. Commenting out the line $mail->IsSMTP();
as noted in the accepted answer may make it work, but it is simply disabling your SMTP configuration, and using the hosting site’s email config.
If you are using GoDaddy, there is no way to send mail using a different SMTP. I was using SiteGround, and found that they were allowing SMTP access from ports 25 and 465 only, with an SSL encryption type, so I would look up documentation for your host and go from there.
answered Apr 6, 2018 at 22:06
StephanieStephanie
1332 silver badges7 bronze badges
<?php
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->IsSMTP();
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mail@gmail.com'; // SMTP username
$mail->Password = 'your pass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('mail@gmail.com');
$mail->addAddress('mail@gmail.com'); // Name is optional
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$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';
}
?>
THIS WORK FOR ME JUST WHEN YOU WANT TO TEST
DON’T USE IDE FOR TESTING THAT BECAUSE PROBABLY NOT WORK IF YOU IN LOCALHOST USE localhost/yourfile.php
answered Mar 17, 2021 at 16:56
the solution is configure the gmail preferences, access to no secure application
CSchulz
10.8k10 gold badges59 silver badges112 bronze badges
answered Jun 6, 2016 at 3:12
0
SMTP connect() failed is a common error in WordPress. If you get the error and hope to know how to solve it, then don’t hesitate to explore the blog today!
Why does the SMTP connect() failed error appear?
Normally, the error SMTP connect() failed turns out because the user misconfigured the SMTP mail sending method (Google Mail Service). Besides that, you know that PHPMailer is the default mailer in WordPress. In case there is something wrong that disallows the PHPMailer to contact the SMTP server, you can also get the error. Further, many other reasons and factors can also cause this error. In order to fix this issue, let’s take a look at the following methods.
How to fix the SMTP connect() failed error
If you desire to address the error SMTP connect() failed in an exact and effective way, it’s a good idea for you to identify the reason first, and then fix it. So, let’s check each possibility now!
SMTP host and port settings
- in the SMTP Host section, fill out your mail server’s name first and ensure that the DNS for the SMTP host is correct.
- The default SMTP port is 25. For mail servers, we will use custom ports 587 for SMTP in order to avoid spam.
- In some cases, the mail servers use firewall rules to restrict access to port 25. If you are in the case, it’s necessary for you to offer your IP white-listed to avoid the error.
- Now, let’s confirm that the connection of the SMTP server and port is good by using the command:
telnet domain.com 25
- After ensuring that the SMTP connection is ok, let’s use the suitable hostname and port number. If the connection is not ok, you will get the error SMTP connect() failed.
SMTP authentication details
As you know, each mail server has an authentication system with the purpose of validating the users before it allows them to connect to it and then send emails. Let’s make sure that the authentication details given are right, if not, WordPress can’t send emails and you may get the error SMTP connect() failed.
SMTP encryption settings
You should select SMTP with encryption if you need the email transmission secure. You can do that by choosing the option ‘Use SSL Encryption’ in the WordPress setting. However, in some email servers, you haven’t turned on SSL/TLS support yet. That means the mail can not get delivered and the error will happen.
Therefore, it’s a good suggestion for you to ensure that you configure the OpenSSL utility correctly in the mail server. Besides that, don’t forget to verify the SSL certificate with the command below:
openssl s_client -starttls smtp -crlf -connect mail.domain.com:25
If you are utilizing expired or self-signed certificates, this may cause the error SMTP connect() failed. Therefore, you can solve this issue by configuring SSL for the mail server or changing the SMTP from encryption to no encryption.
Support for 3rd party apps
Since Gmail servers have many security restrictions, they may block certain mail client apps. If you are in this case, it’s necessary for you to loosen the security. In order to do that, you need to access your Gmail, then open My Account -> Lestt Secure Apps -> Turn on Access for less secure apps.
WordPress SMTP plugins
Sometimes, the error SMTP connect() failed may appear because of the conflict with the SMTP plugin you are using. If this is the reason, you just need to stop using it and find alternative plugins. Here are some recommended WordPress SMTP Plugins for you to try.
Final Words
In conclusion, we are happy to offer you some solutions for the error SMTP connect() failed. If you think the blog is helpful, then don’t hesitate to share it with other users. Besides, don’t forget to leave your comment below if you have trouble related to this topic.
Furthermore, let’s have a look at our well-designed and easy-to-use free WordPress themes here. Thanks for your visit and have a great day!
- Author
- Recent Posts
Welcome to LT Digital Team, we’re small team with 5 digital content marketers. We make daily blogs for Joomla! and WordPress CMS, support customers and everyone who has issues with these CMSs and solve any issues with blog instruction posts, trusted by over 1.5 million readers worldwide.
Welcome to LT Digital Team, we’re small team with 5 digital content marketers. We make daily blogs for Joomla! and WordPress CMS, support customers and everyone who has issues with these CMSs and solve any issues with blog instruction posts, trusted by over 1.5 million readers worldwide.