Ошибка соединения connection refused smtp

I’m new to PHPMailer, and I just downloaded it with Composer and coded this as index.php:

    <?php 
require_once 'vendor/autoload.php';
use PHPMailerPHPMailerPHPMailer;
$m = new PHPMailer;
$m->isSMTP();
$m->SMTPAuth = true;
$m->SMTPDebug = 2;

$m->Host = 'smtp.mail.yahoo.com';
$m->Username = 'vagefipooya@yahoo.com';
$m->Password = 'MY PASSWORD';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->IsHTML(true);

$m->SetFrom('pouyavey@gmail.com');
$m->FromName = 'Pouya Vaghefi';
$m->addReplyTo('pouyavey@gmail.com','Pouya Vey');
$m->addAddress('pouyavey@gmail.com','Pouya Vey');
//$m->addCC('alex@phpacademy','Alex Garret');
//$m->addBCC('alex@phpacademy','Alex Garret');
$m->CharSet = "UTF-8";

$m->Subject = 'Here is an email';
$m->msgHTML("convert HTML into a basic plain-text alternative body");
$m->Body = 'This is the body of an email';
$m->AltBody = 'This is the body of an email';

if (!$m->send()) {
        echo "Mailer Error: " . $m->ErrorInfo;
    } else {
        echo "Message sent!";
    }
    ?>

Then I uploaded it to my site (my site does not use ssl) which is using cPanel and tried to load the page but I got this as error:

2018-04-19 10:03:46 SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP connect() failed. /wiki/Troubleshooting
Mailer Error: SMTP connect() failed.

I also read the related questions to this problem and changed the port from 465 to 587 (with tls), 25 and 26 but couldn’t solve the problem yet.

So can you please help me with this error, cause I really don’t know what to do!

Thanks…

asked Apr 19, 2018 at 10:08

4

This is mostly due to your hosting providers firewall issues. See on below link where someone had similar issue —

https://github.com/PHPMailer/PHPMailer/issues/295

Contact your hosting provider, they will be able to help you

answered Apr 23, 2018 at 13:31

mdeora's user avatar

mdeoramdeora

4,1062 gold badges18 silver badges29 bronze badges

I tried your code with my email and token, also not work, it shows :

2018-04-28 13:52:41     SMTP ERROR: Failed to connect to server:  (0)
2018-04-28 13:52:41     SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

then i changed below two lines:

$m->SMTPSecure = 'ssl';
$m->Port = 465;

to

$m->SMTPSecure = 'tls';
$m->Port = 587;

then, it works

    ...
2018-04-28 13:53:13     SERVER -> CLIENT: 354 Start mail input; end with <CRLF>.<CRLF>
2018-04-28 13:53:13     CLIENT -> SERVER: Date: Sat, 28 Apr 2018 21:53:04 +0800
2018-04-28 13:53:13     CLIENT -> SERVER: To: "feiffy" <example@example.com>
2018-04-28 13:53:13     CLIENT -> SERVER: From: feiffy <feifeifanye@hotmail.com>
2018-04-28 13:53:13     CLIENT -> SERVER: Reply-To: "feiffy" <example@example.com>
2018-04-28 13:53:13     CLIENT -> SERVER: Subject: Here is an email
2018-04-28 13:53:13     CLIENT -> SERVER: Message-ID: <hW4npgJlHQ2CjCqR42xK7j7BRpAzEFAz8mnwK4G6o@pc>
2018-04-28 13:53:13     CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.5 (https://github.com/PHPMailer/PHPMailer)
2018-04-28 13:53:13     CLIENT -> SERVER: MIME-Version: 1.0
2018-04-28 13:53:13     CLIENT -> SERVER: Content-Type: multipart/alternative;
2018-04-28 13:53:13     CLIENT -> SERVER:       boundary="b1_hW4npgJlHQ2CjCqR42xK7j7BRpAzEFAz8mnwK4G6o"
2018-04-28 13:53:13     CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER: This is a multi-part message in MIME format.
2018-04-28 13:53:13     CLIENT -> SERVER: --b1_hW4npgJlHQ2CjCqR42xK7j7BRpAzEFAz8mnwK4G6o
2018-04-28 13:53:13     CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER: This is the body of an email
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER: --b1_hW4npgJlHQ2CjCqR42xK7j7BRpAzEFAz8mnwK4G6o
2018-04-28 13:53:13     CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER: This is the body of an email
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER: --b1_hW4npgJlHQ2CjCqR42xK7j7BRpAzEFAz8mnwK4G6o--
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER: .
2018-04-28 13:53:14     SERVER -> CLIENT: 250 2.0.0 OK <hW4npgJlHQ2CjCqR42xK7j7BRpAzEFAz8mnwK4G6o@pc> [Hostname=SG2PR06MB0776.apcprd06.prod.outlook.com]
2018-04-28 13:53:14     CLIENT -> SERVER: QUIT
2018-04-28 13:53:14     SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel

hope to help you.

answered Apr 28, 2018 at 14:07

feiffy's user avatar

I’ve been using mailgun and I love it. Mailgun.com Totally free for a case like this.

As a suggestion, can you see if there’s a sendmail daemon running on your box? Maybe that will be good enough for your use case?

answered Apr 25, 2018 at 21:35

Lucas's user avatar

LucasLucas

4693 silver badges7 bronze badges

1

These days, an option to send mails is a basic requirement of any web application.

So popular applications like WordPress, Drupal etc. include a mail program called “PHPMailer” for sending mails.

The steps to setup PHPMailer may not be intuitive to many website owners and mistakes in configuration often cause “Smtp error: Failed to connect to server” error.

As part of our Support Services, we help website owners solve their technical issues. And, mail issue related with PHPMailer is an error that we see often .

In this article, we’ll see the top reasons for “Smtp error: Failed to connect” and how we fix them.

What is “Smtp error: Failed to connect to server” ?

Spammers often use php scripts that directly connect to remote servers and send spam mails.

To defend this, many Web Hosting providers block direct connection from websites to external mail servers.

In such servers, mails from website can be sent only via its own mail server (SMTP server) port, just as how Outlook or Windows Mail works.

PHPMailer is a mail application that works like a mail client and helps to send mail via SMTP server.

But, PHPMailer do not work out of the box. It can fail due to firewall restrictions on the server, wrong mail server name, port etc. and shows the error:

“Smtp error: Failed to connect to server”

And, depending on the response from the mail server, we’ve seen 2 variations of this error :

SMTP ERROR: Failed to connect to server: Connection refused (111)

or

SMTP ERROR: Failed to connect to server: Connection timed out (110)

What causes SMTP ERROR: Failed to connect to server ?

Here, let us discuss the top reasons for “SMTP ERROR: Failed to connect to server”.

1. SMTP restrictions on the server.

Servers restrict the programs that can directly connect to remote servers and send mail. Usually, only mail server, root user etc. allow SMTP connections.

For example, CPanel servers block access to external SMTP servers using the “SMTP Restrictions” option.

With this restriction, connection from PHPMailer to an external mail server do not work. The connection wait for some time and eventually die with the following error:

2018-10-12 04:12:37 SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Oops! Something went wrong and we couldn't send your message.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

2. Firewall restrictions on the server

Mail servers accept or reject connections based on certain firewall policies.

All mail servers allow the connection from default mail port 25. Bu,t other mail ports like 465, 587 etc. will not be open in many servers.

On a server with mail port restrictions, when a website owner tries to send mail using an external smtp server on port 465, it ends up in error:

2018-08-28 10:33:12 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): unable to connect to ssl://mail.xyz.com:465 (Connection refused)
2018-08-28 10:33:12 SMTP ERROR: Failed to connect to server: Connection refused (111)

Here, this “Connection Refused” error means that sending mail server refuses outbound connections on port 465 and is not able to connect to remote mail server.

3. Incorrect settings in PHPMailer

This SMTP error can also happen if the mail server name is incorrectly set (with additional white space) in PHPMailer configuration. Then, web form tries to connect to an invalid name and fails.

4. DNS failures

For the PHPMailer to work properly, the mail server specified in its configuration should have proper dns records. When dns do not work on the server, a look up from the server shows wrong IP address or no IP address for the mail server. Again, that causes mail to fail with SMTP error.

How to fix SMTP Error: Failed to connect to server

For mails to work with PHPMailer, both sending and receiving server has to accept connections.

Our Support Engineers primarily checks the connection between mail servers and find whether it is an incoming or outgoing block.

Then, to fix the mail error, we make changes on the server that includes the following :

  1. Modify the firewall rules on the server to allow outbound connections on ports like 465.
  2. Modify the SMTP restrictions on the server. Then, add particular website user to the list of users who can make outbound SMTP connections.
  3. Edit PHPMailer settings like Host, Port etc.
  4. Correct DNS resolution for mail server.

Conclusion

“SMTP ERROR: Failed to connect to server” mainly happens because of mail server connectivity issues, wrong port settings etc. Here, we have discussed the causes that our Support Engineers often see in servers and how we fix them.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

Есть 3 сервера.
1 mailwizz -web программа для отправки писем
2 mailwizz -web программа для отправки писем
3 почтовый сервер

оба mailwiz — по конфигурации вроде как идентичны
на почтовом сервере 587 порт открыт, ограничений на mailwizz сервера нет, все в порядке
mailwizz,ы подключаются к почтовому серверу через smtp
почтовым сервером управляет PMTA, сертификаты настроены — другой майлвиз шлет

проблема:
1 mailwizz — прекрасно коннектится по 587 к почтовому серверу и шлет письма
2 mailwizz — не как не хочет, пишет ошибку

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Connection: opening to m-spf.ru:587, timeout=30, options=array ( 'ssl' => array ( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ),)
Connection failed. Error #2: stream_socket_client(): unable to connect to postal.ru:587 (Connection refused) [/var/www/mailwizz/data/www/mailwizz.ru/apps/common/vendors/Composer/vendor/phpmailer/phpmailer/src/SMTP.php line 387]
SMTP ERROR: Failed to connect to server: Connection refused (111)

на проблемном сервере mailwizz
— панель isp manager
— PHP Version 7.3.19
— SSL Version OpenSSL/1.0.2u
openssl
OpenSSL support enabled
OpenSSL Library Version OpenSSL 1.1.0l 10 Sep 2019
OpenSSL Header Version OpenSSL 1.1.0l 10 Sep 2019
Openssl default config /usr/lib/ssl/openssl.cnf
Native OpenSSL support enabled

все что про него знаю, вроде тоже самое что на другом mailwizz

Как можно мой майлвиз подружить с 587 портом моего почтового сервера.

When I used examples gmail.php (Trying to send mail using gmail account)I get following error message.
» SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting»
My code in gamil.php was

isSMTP();

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;

//Ask for HTML-friendly debug output
$mail->Debugoutput = ‘html’;

//Set the hostname of the mail server
//$mail->Host = ‘tls://smtp.gmail.com:587’;
$mail->Host = ‘smtp.gmail.com’;
// use
// $mail->Host = gethostbyname(‘smtp.gmail.com’);
// if your network does not support SMTP over IPv6

//Set the SMTP port number — 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;

//Set the encryption system to use — ssl (deprecated) or tls
$mail->SMTPSecure = ‘tls’;

//Whether to use SMTP authentication
$mail->SMTPAuth = false;

//Username to use for SMTP authentication — use full email address for gmail
$mail->Username = «mymailid@gmail.com»;

//Password to use for SMTP authentication
$mail->Password = «mypassword»;

//Set who the message is to be sent from
$mail->setFrom(‘mymailid@gmail.com’, ‘First last’);

//Set an alternative reply-to address
$mail->addReplyTo(‘mymailid@gmail.com’, ‘First last’);

//Set who the message is to be sent to
$mail->addAddress(‘sendmail@gmail.com’, ‘first last’);

//Set the subject line
$mail->Subject = ‘PHPMailer GMail SMTP test’;

//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents(‘contents.html’), dirname(**FILE**));

//Replace the plain text body with one created manually
$mail->AltBody = ‘This is a plain-text message body’;

//Attach an image file
$mail->addAttachment(‘images/phpmailer_mini.png’);

//send the message, check for errors
if (!$mail->send()) {
echo «Mailer Error: » . $mail->ErrorInfo;
} else {
echo «Message sent!»;
}

Topic: Connection refused to SMTP  (Read 7748 times)

i’m very glad new beta 2 finally launch, but i have some issue with beta 2

when i try to sending email thru roundcube, there’s always failed to send msg and i check error logs , i found this error

 SMTP Error: SMTP error: Connection failed: Failed to connect socket: Connection refused
 in /path/to/roundcube/program/steps/mail/sendmail.inc on line 253

when i try using PHP Mail() all going well. but i guess PHP Mail() isn’t a good solution to sending an email thru webmail.

Please advice!


Logged


I have the exact same problem, using servage.net. I tried with «user@domain.tdl» instead of %u, and I have tried using all the different AUTH types, to no avail. Any suggestions?

// use this host for sending mails.
// to use SSL connection, set ssl://smtp.host.com
// if left blank, the PHP mail() function is used
$rcmail_config[‘smtp_server’] = ‘smtp1.servage.net’;

// SMTP port (default is 25; 465 for SSL)
$rcmail_config[‘smtp_port’] = 5190;

// SMTP username (if required) if you use %u as the username RoundCube
// will use the current username for login
$rcmail_config[‘smtp_user’] = ‘%u’;

// SMTP password (if required) if you use %p as the password RoundCube
// will use the current user’s password for login
$rcmail_config[‘smtp_pass’] = ‘%p’;

// SMTP AUTH type (DIGEST-MD5, CRAM-MD5, LOGIN, PLAIN or empty to use
// best server supported one)
$rcmail_config[‘smtp_auth_type’] = »;


Logged


Does your smtp server require authentication?

In the config you have there it will try to log onto the SMTP server using the username and password that you logged into RoundCube.
If you don’t normally have to have a username and password to send email — leave it blank -».

// SMTP username (if required) if you use %u as the username RoundCube
// will use the current username for login
$rcmail_config[‘smtp_user’] = »;

// SMTP password (if required) if you use %p as the password RoundCube
// will use the current user’s password for login
$rcmail_config[‘smtp_pass’] = »;

Gary


Logged


i was able to resolve this problem by myself, if you install roundcube in your own server and using cPanel you can re-install exim and set,

// use this host for sending mails.
// to use SSL connection, set ssl://smtp.host.com
// if left blank, the PHP mail() function is used
$rcmail_config[‘smtp_server’] = ‘localhost’;

if you use 127.0.0.1 or IP Address or Domain name (eg. smtp.blabla.com) , connection will refused but i found another issue if using » localhost » as smtp server, see below:

Received: from localhost ([127.0.0.1]:55212 ident=nobody)
   by blablaserver.com with esmtpa (Exim 4.52)

all your msg will ident as » nobody » but i guess it isn’t matter if oidentd not installed on your server or web hosting server.

Try it!


Logged


i’m very glad new beta 2 finally launch, but i have some issue with beta 2

when i try to sending email thru roundcube, there’s always failed to send msg and i check error logs , i found this error

 SMTP Error: SMTP error: Connection failed: Failed to connect socket: Connection refused
 in /path/to/roundcube/program/steps/mail/sendmail.inc on line 253

when i try using PHP Mail() all going well. but i guess PHP Mail() isn’t a good solution to sending an email thru webmail.

Please advice!

i just wanted to say that i had this same problem, and changing $rcmail_config[‘smtp_server’] to «ssl://localhost» worked for me.


Logged


Понравилась статья? Поделить с друзьями:
  • Ошибка соединения cd63 mta province
  • Ошибка соединения cannot allocate logdata message sacred
  • Ошибка соединения call of duty modern warfare
  • Ошибка соединения 90001 panasonic kx ut133
  • Ошибка соединения 90001 panasonic kx ut123