Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ralee's avatar

Email - Connection refused #111

Hi i am stuck for awhile now, hoping some one can help me out here.

I have these configurations on my homestead which works fine, its succesfully sending emails


//config/mail.php
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.office365.com'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => 'info@minghan.sg', 'name' => 'Minghan'],
    'encryption' => 'tls',
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,

//.env
    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.office365.com
    MAIL_PORT=587   
    MAIL_USERNAME=***********
    MAIL_PASSWORD=***********

But when i put the site onto my live server (Godaddy - Shared Hosting) it stopped working and returns this error instead - Connection could not be established with host smtp.office365.com [Connection refused #111]

  1. I have called Godaddy and they have enabled remote email
  2. ports are not blocked.

I am quite lost at the moment & I chance upon this http://stackoverflow.com/questions/15649193/swiftmail-smtp-error

-> Apparently the problem is that there is no mail server installed. So you have to find the server of your choice and to install it. I used postfix and installed it in the following way: sudo apt-get install postfix.

Should i try this? I am not a expert in linux. I am afraid i might screw up my server.

Is there anyone with similar experience? Please guide me through.

Thanks in advance!

Cheers, Ralee

0 likes
13 replies
christopher's avatar

Dont know which problem this is but:

Why dont you use an awesome free service like mailgun or mandrill for sending emails?

ralee's avatar

@hostianer,

Thanks for replying. The thing is i have already purchased and subscribed to office365, having set up my emails as xxx@mydomain.com. It's weird that the same configuration works on my local but not on my server.

Does anyone have any idea what could be causing - Connection could not be established with host smtp.office365.com [Connection refused #111]

Thanks in advance.

Cheers Ralee

billmurrin's avatar

You should not require a mail server, merely a smtp mailer/client/library. Having a mail server would allow you to receive e-mail or allow others to "relay" e-mail off of your webserver = no bueno. You are using an external mail server for a reason, so you don't have to maintain your own and the security risks that come with it.

I stand corrected regarding using the mailx command, appears it would not be supported in Laravel.

For the smtp driver supplied by the Swiftlibrary

The Swift_SmtpTransport and Swift_SendmailTransport transports use proc_* PHP functions, which might not be available on your PHP installation. You can easily check if that's the case by running the following PHP script: <?php echo function_exists('proc_open') ? "Yep, that will work" : "Sorry, that won't work";

More information: http://swiftmailer.org/docs/sending.html

ralee's avatar

update: Apparently shared server have a whole different setup from dedicated server. So this is the configuration that works for my case.

'driver' => env('MAIL_DRIVER', 'sendmail'),
'host' => env('MAIL_HOST', 'localhost'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => '**********', 'name' => '********'],
'encryption' => 'tls',
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -t',
'pretend' => false,

I hope this can help someone out with the same issue as me.

Thanks @hostianer and @billmurrin for replying!

Cheers Ralee

10 likes
willvincent's avatar

email of any sort from godaddy's servers tends to be a huge pain... much moreso than I should be. :)

2 likes
Himalay's avatar

@ralee Thanks mate, It's work for us like charm for godaddy shared hosting.

Thanks again..

cristian495's avatar

seems that shared hosting dont allow to another smtp servers or at least i dont know how to setup it. I solved using the smtp from the selfhosting like this: MAIL_DRIVER=smtp MAIL_HOST=yourdomain MAIL_PORT=587 [email protected] MAIL_PASSWORD=passwordusermail MAIL_ENCRYPTION=tls

lukegalea16's avatar

@ralee where did you setup the sendmail for office365 then please? I am using sendgrid instead - if I use sendmail instead of smtp how can I specify the host

Please or to participate in this conversation.