Ошибка отправки smtp connect failed

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's user avatar

AnFi

10.4k3 gold badges23 silver badges47 bronze badges

asked Aug 28, 2013 at 19:29

andy's user avatar

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's user avatar

dario

5,12912 gold badges28 silver badges32 bronze badges

answered Aug 10, 2015 at 12:51

Snehasis's user avatar

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 David's user avatar

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";

Community's user avatar

answered Aug 29, 2013 at 20:58

Dmitri DB's user avatar

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

Sendoh Akira's user avatar

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

Goldbug's user avatar

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

user5778000's user avatar

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's user avatar

Daniel

1,22914 silver badges24 bronze badges

answered Dec 27, 2016 at 22:07

Hieu.Gi's user avatar

Here is a list of this you should look into when dealing with PHPMailer:

  1. Enable openSSL by un-commenting extension=php_openssl.dll in your PHP.ini
  2. Use $mail->SMTPSecure = 'tls'; and $mail->Port = 587;
  3. Enable debugging for if you are going wrong somewhere else like incorrect username and password etc.

answered May 14, 2015 at 7:02

KKK's user avatar

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 Kumar's user avatar

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 Coronel's user avatar

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

Akif Hussain Sayyed's user avatar

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

Stephanie's user avatar

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

MAX's user avatar

the solution is configure the gmail preferences, access to no secure application

CSchulz's user avatar

CSchulz

10.8k10 gold badges59 silver badges112 bronze badges

answered Jun 6, 2016 at 3:12

marcelo's user avatar

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

Lt Digital Team (Content &Amp; Marketing)

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.

Lt Digital Team (Content &Amp; Marketing)

@ErfanImmortal

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.

Lt Digital Team (Content &Amp; Marketing)

i have problem with PHPmailer and get
Message could not be sent.Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Debug output

<?php

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;

require 'PHPmailer/src/Exception.php';
require 'PHPmailer/src/PHPMailer.php';
require 'PHPmailer/src/SMTP.php';
$mail = new PHPMailer;                              // Passing `true` enables exceptions


    //Server settings
	$mail->isSMTP();                                      // Set mailer to use SMTP
	$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'arzaangift@gmail.com';                 // SMTP username
    $mail->Password = '**********';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to
    //Recipients
    $mail->setFrom('admin@marveliptv.com', 'Marvel IPTV');
    $mail->addAddress('karyab13052@gmail.com');     // Add a recipient
    $mail->addReplyTo('marvelteam.sup@gmail.com');
    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Salam' ;

	$mailContent = '
<h2>Eri</h2>
<p>Eri</p>
<p>Eri</p>';

    $mail->Body    = $mailContent ;
    $mail->send();

if(!$mail->send()){
    echo 'Message could not be sent.';
    echo 'Error: '. $mail->ErrorInfo;
}else{
	echo 'Message has been sent';
}	

?>

@Synchro

Please follow the link to the troubleshooting guide in the error message which gives details of how to diagnose this exact problem.

@ErfanImmortal

2019-02-28 12:00:46 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
2019-02-28 12:00:47 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:587 (Network is unreachable) [/home/marvemhc/public_html/lab2/PHPmailer/src/SMTP.php line 327]
2019-02-28 12:00:47 SMTP ERROR: Failed to connect to server: Network is unreachable (101)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
2019-02-28 12:00:47 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
2019-02-28 12:00:48 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:587 (Network is unreachable) [/home/marvemhc/public_html/lab2/PHPmailer/src/SMTP.php line 327]
2019-02-28 12:00:48 SMTP ERROR: Failed to connect to server: Network is unreachable (101)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Please follow the link to the troubleshooting guide in the error message which gives details of how to diagnose this exact problem.

@ErfanImmortal

if i disable this line , email will be send
«//$mail->isSMTP(); // Set mailer to use SMTP»

@Synchro

That means you’re not using SMTP. It looks like your ISP blocks you from using outbound SMTP, which is exactly what the guide says. When it says «network is unreachable» , it means it can’t reach your network for sending via SMTP. Bear in mind that while sending may «work», you’re likely to run into problems because you’re forging your from address.

@ErfanImmortal

So i solve my previous problem
but i have new problem
if get this error
Invalid address: (to):
Message could not be sent.Error: You must provide at least one recipient email address.

i have form.html with this code

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>Send Email</title>
<link rel="stylesheet" type="text/css" href="main.css">	
<script  src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
	<!--[if IE]><script>
	$(document).ready(function() { 
$("#form_wrap").addClass('hide');
})
</script><![endif]-->
</head>
<body>
	<div id="wrap">
		<div id='form_wrap'>
			<form action="submit.php" method="post">
				<p>Send Email</p>
				<label for="email">Email </label>
				<input type="text" name="emailphp" value="" id="emailphp" />	
				<label for="subject">Subject </label>
				<input type="text" name="subjectphp" value="" id="subjectphp" />
				<label for="message">Your Message : </label>
				<textarea  name="messagephp" value="Your Message" id="messagephp" ></textarea>				
				<input type="submit" name ="submit" value="Now, Send!" />
			</form>
		</div>
	</div>
</body>
</html>

and i have «submit.php» too

<?php

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;

require 'PHPmailer/src/Exception.php';
require 'PHPmailer/src/PHPMailer.php';
require 'PHPmailer/src/SMTP.php';
$mail = new PHPMailer;                              // Passing `true` enables exceptions

if (isset($_POST['submit'])) {
    $emailinp = $_POST['email'];
    $subjectinp = $_POST['subject'];
    $messageinp = $_POST['message'];
}

    //Server settings
	$mail->SMTPDebug = 4; 
	$mail->isSMTP();                                      // Set mailer to use SMTP
	$mail->Host = 'server119.web-hosting.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'admin@marviiii.com';                 // SMTP username
    $mail->Password = '*******';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to
    //Recipients
    $mail->setFrom('admin@marviiii.com', 'Mari');
    $mail->addAddress($emailinp); 
    $mail->addReplyTo('marviiii@gmail.com');
    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = $subjectinp ;

	$mailContent = '
<h2>Eri</h2>
<p>Eri</p>
<p>Eri</p>';

    $mail->Body    = $mailContent ;

if(!$mail->send()){
    echo 'Message could not be sent.';
    echo 'Error: '. $mail->ErrorInfo;
}else{
	echo 'Message has been sent';
}	

?>

@ErfanImmortal

<?php

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;

require 'PHPmailer/src/Exception.php';
require 'PHPmailer/src/PHPMailer.php';
require 'PHPmailer/src/SMTP.php';
$mail = new PHPMailer;                              // Passing `true` enables exceptions

if (isset($_POST['submit'])) {
    $emailinp = $_POST['email'];
    $subjectinp = $_POST['subject'];
    $messageinp = $_POST['message'];
}

    //Server settings
	$mail->SMTPDebug = 4; 
	$mail->isSMTP();                                      // Set mailer to use SMTP
	$mail->Host = 'server.web-hosting.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'admin@marii.com';                 // SMTP username
    $mail->Password = '********';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to
    //Recipients
    $mail->setFrom('admin@marii.com', 'Mariii');
    $mail->addAddress($emailinp); 
    $mail->addReplyTo('test@gmail.com');
    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = $subjectinp ;

	$mailContent = '
<h2>Eri</h2>
<p>Eri</p>
<p>Eri</p>';

    $mail->Body    = $mailContent ;

if(!$mail->send()){
    echo 'Message could not be sent.';
    echo 'Error: '. $mail->ErrorInfo;
}else{
	echo 'Message has been sent';
}	

?>

@Synchro

You’re only using the submit check to set variables — you’re still trying to send anyway, even if it’s not a submission. You’ve also got no error checking on the addAddress call, in case someone submits an invalid address (it returns false if the address is bad).

@ErfanImmortal

You’re only using the submit check to set variables — you’re still trying to send anyway, even if it’s not a submission. You’ve also got no error checking on the addAddress call, in case someone submits an invalid address (it returns false if the address is bad).

thanks
solved
my next problem is smtp with send grid
how can i send email with sendgrid smtp?

@Synchro

It should be a matter of changing the Host, Username and Password properties — but read their docs.

@ap1437

@Synchro

This may come as a bit of a surprise, but you might want to click that link and read what it says?

@PHPMailer
PHPMailer

locked as resolved and limited conversation to collaborators

May 28, 2021

Выдает Ошибка: SMTP connect() failed.

<?php 

$name = $_POST['user_name'];
$phone = $_POST['user_phone'];

require_once('phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->CharSet = 'utf-8';

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'danil.plotnikov111@gmail.com';                 // Наш логин
$mail->Password = 'danil27082001';                           // Наш пароль от ящика
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to
 
$mail->setFrom('danil.plotnikov111@gmail.com', 'danil');   // От кого письмо 
$mail->addAddress('danil.plotnikov111@gmail.com');     // Add a recipient
//$mail->addAddress('ellen@example.com');               // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Новая заявка';
$mail->Body    = '
	Пользователь оставил свои данные <br> 
	Имя: ' . $name . ' <br>
	Телефон: ' . $phone . '';

$mail->AltBody = 'Это альтернативный текст';

if(!$mail->send()) {
    echo "error";
    echo 'Ошибка: ' . $mail->ErrorInfo;
} else {
    echo "success";;
}

?>

В гугл разрешил отправку с неизвестных источников

WordPress is the most widely used CMS for websites. Sending out mails from WordPress is required in scenarios such as contact form submissions or password resets.

‘SMTP connect() failed‘ is a commonly encountered error in WordPress, due to which emails fail to be send from your WordPress site.

Configuring email settings in WordPress

By Default, WordPress uses the PHP Mail function to send emails. But using PHP mail function is a less secure method and makes the server vulnerable to spamming.

As a result, many webservers have PHP mail() function disabled for security purposes. In those servers, mails can be send from WordPress using SMTP.

SMTP uses proper authentication and is therefore more secure. There are WordPress plugins such as ‘WP Mail SMTP‘, that has to be configured to send mails via SMTP.

Once the SMTP plugin is activated, a new ‘Email‘ menu will show up under the Settings in WP. You can configure the email delivery settings in that option.

Configure SMTP plugin in WordPress

Configure SMTP plugin in WordPress

You can give your email address, password, mail server name and port in the Email settings and save it. You can test the mail delivery to see if the settings are fine.

The following settings can be configured in the Email settings:

From Email - the email address you want to send emails from 
From Name - the name that your emails will be received from
Mailer - you can choose between the default PHP Mail function and SMTP
SMTP Host - the hostname for your SMTP server
SMTP Port - the port for your mail server, usually 25
Encryption - if you want to enable SSL/TLS encryption for the mail server
Authentication - check it for mail server authentication
Username - the username for your SMTP server
Password - the password for your SMTP server

What causes error ‘SMTP connect() failed’ in WordPress

The default mailer is PHPMailer in WordPress and many sites use it to send mails. But it can give ‘SMTP connect() failed’ error if PHPMailer is unable to contact the SMTP server.

SMTP connect() failed error in WordPress

SMTP connect() failed error in WordPress

Also, if the settings for the SMTP server is not configured correctly, it will not send mails successfully from the server and give ‘SMTP connect() failed’ error.

The error ‘SMTP connect() failed’ can be caused due to the many reasons, which we’ll discuss one by one.

Wrong username and password given in SMTP authentication.

SMTP port blocked in mail server firewalls.

SSL/TLS not support in mail server and encryption is enabled in WP setting.

Security restrictions by 3rd party servers such as gmail or email apps.

Upgrades to WordPress plugin or PHPMailer versions that have enhanced security features or bugs.

How to fix error ‘SMTP connect() failed’ in WordPress

To fix the error, first thing is to do is to identify the cause for the error, by checking and ruling out each possibility.

1. SMTP host and port settings

Enter the name of your mail server in ‘SMTP Host’ section. This is usually the ‘domain name’ or ‘mail.domain.com’. Make sure that the DNS for SMTP host resolves correctly.

Give port number as 25, the default SMTP port. For mail servers that use custom ports such as 587 for SMTP to avoid spamming, give that port.

It is also possible that certain mail servers restrict the access to their port 25 using firewall rules. In such cases, your IP should be white-listed in the firewall to avoid SMTP error.

To confirm that the connectivity to SMTP server and port is working fine, use the command:

telnet domain.com 25

Use the appropriate hostname and port number, after confirming that the SMTP connection is working fine.

If the connectivity fails to establish, mail delivery will fail with the error ‘SMTP connect() failed‘.

2. SMTP authentication details

Every mail server has an authentication system to validate the users before allowing them to connect to it and send mails. In your WordPress Email settings, enter these details.

Give the email account username and password. Enter the full ‘user@domain.com’ as the username in case of non-default accounts.

Whenever the email account password is changed or updated for security reasons, do not forget to change the password in ‘Email settings’ also.

If the authentication details given are wrong, WordPress will fail to send mails and give the error ‘SMTP connect() failed‘.

3. SMTP encryption settings

For secure email transmission, it is always advisable to choose SMTP with encryption. This can be done using ‘Use SSL encryption’ option in WordPress setting.

But is some email servers, this SSL/TLS support may not be enabled. In those cases, if you choose encryption, mails may not get delivered.

Make sure that the ‘openssl’ utility is configured properly in your email server. Also, verify the SSL certificate for your mail server, using the command:

openssl s_client -starttls smtp -crlf -connect mail.domain.com:25

Using expired or self-signed certificates can cause the mail delivery using SSL to fail and give error ‘SMTP connect() failed‘.

So the solution in those cases is to configure SSL for your mail server properly or change the SMTP encryption to ‘No Encryption’, which is less secure one.

4. Support for 3rd party apps

Gmail servers have a lot of security restrictions in place, which may cause them to block attempts from certain mail client apps.

In those cases, you will have to loosen the security measures. In gmail, go to ‘My Account’ -> ‘Less Secure Apps‘ section, and turn on the option ‘Access for less secure apps‘.

Allow less secure apps in gmail account

Allow less secure apps in gmail account

If you are using Gmail as your mail server, then a better option is to install and activate the ‘Gmail SMTP’ plugin for WordPress.

5. WordPress SMTP plugins

Lastly, the SMTP plugin related issues can also cause ‘SMTP connect failed’ error. In those cases, you will have to stop using ‘WP Mail SMTP’ plugin and choose other ones.

Some WordPress SMTP plugins that can be used are Postman SMTP Mailer, Mailgun, etc. for sending mails from WordPress sites.

In short..

Other variants for ‘SMTP connect() failed’ error are ‘Called Mail() without being connected’ or ‘SMTP Error: Could not connect to SMTP host.’

In addition to the configuration settings we’ve discussed, one important point to keep in mind is the safety precautions to take during WordPress or PHPMailer upgrades.

At Bobcares, our hands-on experience with both WordPress customization and server administration has helped us to perform upgrades and fixes in websites without causing any business downtime.

If you’d like to know how to secure and manage your servers and customize your websites to prevent errors, we’d be happy to talk to you.

Get an EXPERT consultation

Do you spend all day answering technical support queries?

Wish you had more time to focus on your business? Let us help you.

We free up your time by taking care of your customers and servers. Our engineers monitor your servers 24/7, and support your customers over help desk, live chat and phone.

Talk to our technical support specialist today to know how we can keep your service top notch!

TALK TO AN EXPERT NOW!

var google_conversion_label = «Blp0CLCojHIQ0aD71QM»;

Понравилась статья? Поделить с друзьями:
  • Ошибка отправки sms с телефона
  • Ошибка отправки sms на номер
  • Ошибка отправки mail ru приложение
  • Ошибка отправки error authentication failed invalid user or password
  • Ошибка отправить отчет об ошибке ксиоми