Exchange Connection Problems

Fix Office 365 SMTP Connection Refused from PHP Hosting

Anum MushtaqAnum Mushtaq Nov 25, 2026 868 views

Question details

The user needs to send email from a PHP application hosted on GoDaddy through Office 365.

Fix Office 365 SMTP Connection Refused from PHP Hosting
Product
Microsoft 365 Exchange Online SMTP
Device & OS
not provided
Scenario
A PHP email script needs an outbound SMTP connection to send mail through an Office 365 mailbox.
Observed behavior
The connection to smtp.office365.com or an Exchange Online protection host is refused, even though the domain's DNS records may be correct.
Before you start

Confirm which mail-flow method the PHP application is intended to use and identify the SMTP host, port, and encryption settings in its mailer configuration. Make sure you can run a network test from the same hosting environment as the PHP script.

Solution 1Recommended

Configure Exchange Online SMTP client submission

Use this method when the application sends mail through a licensed Exchange Online mailbox.

A refused connection occurs before SMTP authentication, so correct credentials alone cannot fix a blocked or unreachable port. SMTP client submission uses STARTTLS on port 587; an Exchange Online protection host is used for other mail-flow methods with different requirements.

1
Set the SMTP endpoint

In the PHP mailer's SMTP settings, set the server to smtp.office365.com, the port to 587, and encryption to STARTTLS. Do not select implicit SSL on port 587.

2
Configure the mailbox

In the mailer's authentication settings, use a valid Exchange Online mailbox and an authentication method supported by both the application and Microsoft 365, such as OAuth 2.0. Set the From address to that mailbox unless the account has the appropriate permission to send as another address.

3
Check SMTP AUTH

In the Microsoft 365 admin center, open Users > Active users, select the mailbox, and check Mail > Manage email apps for Authenticated SMTP. Also check whether your organization's policies permit the selected authentication method.

4
Test the connection

From the PHP hosting environment, run `openssl s_client -starttls smtp -connect smtp.office365.com:587` if OpenSSL is available. If the connection is refused or times out, investigate the hosting network before changing mailbox credentials.

Configure Exchange Online SMTP client submission
DNS is not an outbound-port test: Correct domain DNS records do not establish that the hosting provider allows outbound connections to port 587.
Free Microsoft Office alternative

Prepare email attachments with WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for creating and editing Office documents. Its format compatibility makes it easy to move existing files into WPS, although it does not fix Exchange Online SMTP or hosting network restrictions.

Create and edit documents that can be attached to email messages.Compatible with Microsoft Office formats, including DOCX, XLSX, and PPTX.Use a familiar interface to transition from Microsoft Office.Work with documents in a free, lightweight office suite.
microsoft office alternative - wps office

Frequently Asked Questions

Which server and port should PHP use for Office 365 SMTP submission?

Set the PHP mailer's SMTP host to smtp.office365.com and its port to 587, with STARTTLS enabled. Use a supported authentication method and a valid Exchange Online mailbox.

Why is my SMTP connection refused even though my DNS records are correct?

DNS records do not guarantee outbound network access. Run a port 587 connection test from the PHP hosting environment, then ask the hosting provider whether its firewall or hosting plan blocks outbound SMTP.

Where can I check whether SMTP AUTH is enabled for a mailbox?

In the Microsoft 365 admin center, go to Users > Active users, select the mailbox, and open Mail > Manage email apps. Check Authenticated SMTP and verify that organization policies also permit the intended authentication method.

Can I replace smtp.office365.com with an Exchange Online protection host?

Not without changing the mail-flow configuration. Exchange Online protection hosts are used for other methods, such as relay or direct send, which have different connection and configuration requirements.