Fix SMTP Connection Refused Error 111 in PHPMailer (Microsoft 365)
Question details
The user is encountering an 'SMTP ERROR: Failed to connect to server: Connection refused (111)' message when attempting to send emails using PHPMailer through Microsoft 365 Exchange.

- Product
- PHPMailer and Microsoft 365 Exchange
- Device & OS
- not provided
- Scenario
- Configuring a web application with PHPMailer to send outbound emails via Microsoft 365 Exchange servers.
- Observed behavior
- The connection to the Microsoft 365 SMTP server fails, resulting in a Connection Refused (111) error, preventing the web application from sending emails.
Ensure you have administrator access to your Microsoft 365 admin center and verify with your hosting provider that standard outbound email ports are unblocked on your web server.
Enable Authenticated SMTP in Microsoft 365 Admin Center
Microsoft 365 disables SMTP authentication by default for security, which blocks client submissions from tools like PHPMailer. Enabling this for the specific email account often resolves the issue.
By default, Exchange Online disables Basic Authentication and Authenticated SMTP to protect user accounts. If your application relies on SMTP client submission, you must explicitly enable Authenticated SMTP for the mailbox used by PHPMailer.
Log in to the Microsoft 365 admin center. Navigate to the left menu, click on 'Users', and then select 'Active users'.
Find and click on the specific user account that PHPMailer is using to authenticate and send emails.
In the user's details pane that slides out, click on the 'Mail' tab. Under the Email apps section, click on 'Manage email apps'.
Check the box next to 'Authenticated SMTP' to enable it for this account, then click 'Save changes'.

Check Hosting Provider Firewall and Port Blocks
Many web hosting providers block standard outbound email ports (like port 25, 465, or 587) to prevent spam, causing a connection refused error.
Verify PHPMailer Configuration Settings
Ensure that your PHPMailer script uses the correct hostname, port, and encryption methods required by Microsoft 365.
Looking for a Lightweight Alternative to Microsoft Office?
If managing expensive Microsoft 365 subscriptions and complex Exchange configurations is slowing your business down, consider switching to WPS Office. It provides a free, highly compatible suite for standard document management without the overhead.
- 1. Download WPS Office: Visit the official WPS website and download the free installation package for your operating system.
- 2. Install the Suite: Run the installer and follow the simple on-screen instructions to set up WPS Office on your device.
- 3. Open Office Files: Instantly open, edit, and save your existing Word, Excel, and PowerPoint files without formatting issues.

Frequently Asked Questions
Does Error 111 mean my MX records are incorrectly configured?
No. MX records are used by external mail servers to locate your server for incoming mail. The Connection Refused (111) error indicates an outbound connectivity issue, meaning your web server cannot reach the outgoing SMTP host due to network blocks or configuration errors.
Which SMTP host and port should I use for Microsoft 365 in PHPMailer?
You should use 'smtp.office365.com' as the host, port 587, and enable STARTTLS encryption. Ensure that your account has Authenticated SMTP enabled in the Microsoft 365 Admin Center.
How can I tell if my web hosting provider is blocking outbound SMTP connections?
You can test outbound connectivity by logging into your web server via SSH and running the command 'telnet smtp.office365.com 587'. If the connection fails or hangs, your hosting provider's firewall is likely blocking the outbound traffic, and you will need to ask them to open port 587.




