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

enadabuzaid's avatar

Email Not Sending in Laravel 12 with Outlook Web App (Exchange) — Tried SMTP Setup

Hi everyone,

I'm working on a Laravel 12 project, and I need to configure email sending using our internal Outlook Web App (Exchange) server.

Here’s the context:

Our webmail URL is: https://mail.je****.com

I log in using:

Username: je****\kh**********. ( Domain\ username )

Once logged in, my email shows as: kh********@je****.com

I followed the standard SMTP setup in Laravel and updated my .env file like this:

MAIL_MAILER=smtp
MAIL_HOST=mail.je****.com
MAIL_PORT=587
MAIL_USERNAME=kh********@je****.com
MAIL_PASSWORD=********
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=kh********@je****.com
MAIL_FROM_NAME="${APP_NAME}"
MAIL_EHLO_DOMAIN=mail.je****.com

and my mail config

        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST'),
            'port' => env('MAIL_PORT'),
            'encryption' => env('MAIL_ENCRYPTION'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => 10,
            'local_domain' => env('MAIL_EHLO_DOMAIN'),
        ],

✅ I ran php artisan config:clear && php artisan config:cache.

💥 Problem:

Emails are not sending, and I get either:

  • Connection could not be established... wrong version number

  • Or timeout errors when trying to connect

🧪 Tried:

  • Switched between ports 465 (ssl), 587 (tls), and even 25

  • Used both kh*****@je***.com. and je***\kh****** as usernames

  • Disabled SSL verification using stream options (no effect)

❓My Questions:

Has anyone successfully set up Laravel with Outlook Web App that uses domain-based logins (domain\user)?

Is there a way to debug authentication issues in more detail?

If anyone faced a similar setup, or knows whether Laravel works better with EWS or Microsoft Graph API in this case, I’d really appreciate your advice.

Thanks so much in advance! 🙏

0 likes
1 reply
LaryAI's avatar
Level 58

To address the issue of sending emails from Laravel using an Outlook Web App (Exchange) server, there are a few steps and considerations you can take:

  1. Verify SMTP Credentials and Configuration:

    • Double-check the SMTP credentials (username and password) to ensure they are correct.
    • Ensure that the MAIL_HOST is correctly set to the SMTP server address.
    • Confirm that the MAIL_PORT is correct. Typically, port 587 is used for TLS, and port 465 for SSL. Port 25 is less secure and often blocked by ISPs.
  2. Use Correct Username Format:

    • Since you mentioned using domain-based logins, try using the full email address as the username (kh********@je****.com) if you haven't already. Some servers require the full email address rather than the domain\username format.
  3. Check Firewall and Network Restrictions:

    • Ensure that your server can reach the SMTP server. Sometimes, firewalls or network restrictions can block outgoing connections on certain ports.
  4. Enable Debugging:

    • To get more detailed error messages, you can enable debugging in your config/mail.php by setting the log channel temporarily:
      'log' => [
          'transport' => 'log',
          'channel' => env('MAIL_LOG_CHANNEL', 'stack'),
      ],
      
    • This will log all email sending attempts to your Laravel log files, which can help diagnose the issue.
  5. Consider Using Microsoft Graph API:

    • If SMTP continues to be problematic, consider using the Microsoft Graph API for sending emails. This approach can be more reliable and secure, especially with modern authentication methods.
    • You can use the microsoft/microsoft-graph package to interact with the Graph API. Here's a basic setup:
      composer require microsoft/microsoft-graph
      
    • You will need to register an application in Azure AD and obtain the necessary credentials (client ID, client secret, and tenant ID).
  6. Test with a Simple SMTP Client:

    • Use a simple SMTP client like telnet or an email client to test the SMTP connection outside of Laravel. This can help determine if the issue is with the server configuration or the Laravel setup.
  7. Consult Exchange Server Logs:

    • If you have access to the Exchange server logs, check them for any errors or connection attempts from your Laravel application. This can provide insights into what might be going wrong.

By following these steps, you should be able to diagnose and resolve the issue with sending emails from Laravel using your Outlook Web App (Exchange) server. If the problem persists, consider reaching out to your IT department or email server administrator for further assistance.

Please or to participate in this conversation.