New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMTP ERROR: Failed to connect to server: Connection refused (111) with Office365 #295

Closed
ndub opened this Issue Oct 11, 2014 · 11 comments

Comments

Projects
None yet
6 participants
@ndub

ndub commented Oct 11, 2014

Sorry if this is a road heavily traveled. I've seen the other posts about this but nothing in them has either solved the problem I'm having or ignited a lightbulb that helped me solve it myself.

Here's my code:

require 'PHPMailerAutoload.php';
$config = parse_ini_file('/path/to/file/config.ini', true);
$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->Debugoutput = 'html';
$mail->isSMTP();
$mail->Host = $config['host']; //smtp.office365.com
$mail->SMTPAuth = true;
$mail->Username = $config['username']; //an.existing.account@appinc.co
$mail->Password = $config['password']; //confirmed this is being passed correctly
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = $config['username'];
$mail->FromName = 'Website Forms';
$mail->addAddress('sales@appinc.co', 'Some Name');
$mail->addReplyTo('sender.email@somedomain.com', 'SenderFirst SenderLast');
$mail->addBCC('my.email.address@appinc.co');
$mail->isHTML(true);
$mail->Subject = 'Contact Form Submission';
$mail->Body = 'Some html here';
$mail->AltBody = 'Some alt content here';
if(!$mail->send()) {
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    //perform success actions
    exit();
}

I've confirmed that the domain, username and password are all correct and being passed in correctly. Important to note that this worked on our local dev server prior to launch. Once the site was moved to our hosting account (Hostgator) is when it stopped working. I've confirmed with HG that port 587 is open on our server.

Here is the error message I'm seeing:

Connection: opening to smtp.office365.com:587, t=10, opt=array ()
SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP connect() failed.
Message could not be sent.Mailer Error: SMTP connect() failed.

Any help that can be provided is very much appreciated, even if it's just a link to an article that explains why it won't work now that it's in our production environment.

[EDIT]: Minor grammatical error.

@drmad

This comment has been minimized.

drmad commented Oct 12, 2014

This sounds like a network/sysadmin problem, not a PHPMailer problem. Try a

telnet smtp.office365.com 587

in your console, for checking conectivity. If everything is working ok, it should write a message like 'ESMTP MAIL Service ready'. Otherwise that server is blocking yours.

@ndub

This comment has been minimized.

ndub commented Oct 12, 2014

@drmad Thanks!

I've checked the 587 ports on both servers - mine and smtp.office365.com - with telnet and nmap. They both appear to be open and responding. Because I'm on a shared hosting account (Hostgator, cPanel), I don't have terminal access on my web server (that I can find), unless you know some way for me to run the telnet remotely. Sorry, I'm not very versed in telnet usage.

Here's the response from telnet to smtp.office365.com:

Trying 132.245.81.178...
Connected to outlook-namsouth.office365.com.
Escape character is '^]'.
220 BY2PR06CA037.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sun, 12 Oct 2014 00:38:36 +0000

And here is the response from my host server:

Trying 192.254.235.140...
Connected to appinc.co.
Escape character is '^]'.
220-gator3253.hostgator.com ESMTP Exim 4.82 #2 Sat, 11 Oct 2014 19:39:34 -0500 
220-We do not authorize the use of this system to transport unsolicited, 
220 and/or bulk e-mail.

Thanks in advanced for any extra help you can provide.

@drmad

This comment has been minimized.

drmad commented Oct 12, 2014

Perhaps office365.com is blocking your hostgator server. The fastest (and easiest) way is creating a support ticket in hostgator for they to check that conectivity issue.

@Synchro

This comment has been minimized.

Member

Synchro commented Oct 12, 2014

You say you have no terminal access to your server, so I'm guessing those examples you posted are done from somewhere else so the fact that you can get to them doesn't mean that you can from your hostgator server. It could also be a DNS issue on your hostgator config.

@ndub

This comment has been minimized.

ndub commented Oct 12, 2014

Thanks for the advice @Synchro. I contacted HG, again, and asked them about the DNS and could there be anything in the firewall that would be blocking outbound traffic. Sure enough, it was the firewall. They made a change and now it works great! Really appreciate your and @drmad's help!

@Synchro

This comment has been minimized.

Member

Synchro commented Oct 12, 2014

Glad you sorted that out.

@Synchro Synchro closed this Oct 12, 2014

@ndub

This comment has been minimized.

ndub commented Nov 9, 2015

My problem was ultimately resolved by contacting my host and having them
change the way the firewall was configured for my site. If you haven't, I'd
contact your host or look at your firewall settings.

On Mon, Nov 9, 2015 at 12:01 PM, hargrig notifications@github.com wrote:

hey friends i have error like this, can anybody help me ? ))

SMTP ERROR: Failed to connect to server: php_network_getaddresses:
getaddrinfo failed: No address associated with hostname (0)
SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting


Reply to this email directly or view it on GitHub
#295 (comment)
.

@hargrig

This comment has been minimized.

hargrig commented Nov 9, 2015

Thanks bro..i will try that ))

@sahilsunesara

This comment has been minimized.

sahilsunesara commented May 11, 2017

@ndub did u get solution regarding above matter?

@mrshiru

This comment has been minimized.

mrshiru commented Dec 25, 2017

2017-12-25 11:02:41 Connection: opening to ssl://smtp.gmail.com:587, timeout=300, options=array ( ) 2017-12-25 11:02:41 SMTP ERROR: Failed to connect to server: (0) 2017-12-25 11:02:41 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mail Not Send

@Synchro

This comment has been minimized.

Member

Synchro commented Dec 25, 2017

Read the guide the error links to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment