Fix Office 365 SMTP Connection Timeouts in a PHP Application
Question details
The user needs to resolve an Office 365 SMTP timeout in a PHP web application that sends mail using authenticated submission.

- Product
- Microsoft 365 Exchange Online
- Device & OS
- not provided
- Scenario
- A PHP application connects to smtp.office365.com on port 587 and may send messages using different From addresses.
- Observed behavior
- The SMTP connection times out; a command-line test reported that the network was unreachable.
Run the connectivity tests from the web server or container that executes PHP, not just from your own computer. Have the application's SMTP settings and access to the server's firewall or hosting controls ready.
Check Network Access to the Office 365 SMTP Endpoint
Use this first when the connection times out or reports that the network is unreachable.
On the web server, run `nslookup smtp.office365.com` or `dig smtp.office365.com` and confirm that the hostname resolves. If it does not, check the server's DNS configuration.
Run `nc -vz smtp.office365.com 587` from the same environment as the application. If the connection fails or times out, check outbound firewall rules, routing, and hosting-provider restrictions for TCP port 587.
If both address families are returned, test them separately with `nc -4 -vz smtp.office365.com 587` and `nc -6 -vz smtp.office365.com 587`. A network-unreachable error can indicate a missing route for the affected address family; ask the server administrator to correct it.
After TCP connectivity works, run `openssl s_client -starttls smtp -connect smtp.office365.com:587 -servername smtp.office365.com` to check the TLS handshake and certificate verification. Investigate certificate trust or TLS errors reported by the command.

Verify Authenticated SMTP Submission and Sender Permissions
Use this after the server can reach port 587 but the application still cannot submit mail.
Configure an Exchange Online SMTP Relay Connector
Use SMTP relay instead of authenticated client submission when your organization requires connector-based sending and meets its prerequisites.
Work with Office Files in WPS Office
WPS Office is a free, lightweight alternative for working with documents, spreadsheets, and presentations. Its familiar interface and Office format support make it easy to move existing files, although it does not repair Exchange Online SMTP connections.

Frequently Asked Questions
What does a network-unreachable error mean for SMTP?
It usually means the server has no usable route to the selected destination address. Test IPv4 and IPv6 separately from the web server, then check routing and outbound firewall rules.
Should I use SSL or STARTTLS on port 587?
For authenticated submission to smtp.office365.com on port 587, configure STARTTLS with TLS 1.2 or later. Do not select implicit SSL for that port.
Can my application send from a different mailbox?
It may do so if the authenticated account has the appropriate Send As permission for that mailbox. First test with the authenticated mailbox in the From field, then configure and verify permissions for the other address.
Why does SMTP still fail after port 587 is reachable?
Check the TLS handshake, SMTP AUTH settings, supported authentication method, and sender permissions. Look at the application's SMTP error log to determine which stage fails.
Which endpoint does Exchange Online SMTP relay use?
Connector-based SMTP relay normally uses your Microsoft 365 domain's MX endpoint on port 25, not smtp.office365.com on port 587. The connector must identify the sending server by an allowed public IP address or a supported certificate configuration.




