Fix Office 365 SMTP Connection Refused from PHP Hosting
Question details
The user needs to send email from a PHP application hosted on GoDaddy through Office 365.

- 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.
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.
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.
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.
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.
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.
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.

Ask the hosting provider to check outbound SMTP access
Use this approach if a connection test from the hosting environment is refused or times out.
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.

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.




