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

TerrePorter's avatar

sending mail cert issue

Hello, So I have a issue where Laravel is grabbing the wrong ssl cert appernaly. This is the error I get,

Unable to connect with STARTTLS: stream_socket_enable_crypto(): Peer certificate CN=`mi3-ts7.a2hosting.com' did not match expected CN=`mx4125.usc1.mymailhosting.com'

The hosting company replied with the following.

It should be the mail certificate should be pointing to mx4125.usc1.mymailhosting.com, which is your mail domain for xxx.
This hostname: mi3-ts7.a2hosting.com is for the Website SSL certificate name, which is why we need to configure your website is get the website SSL Certificate instead of mail hostname certificate.

Does anyone know how to do what they are asking?

0 likes
1 reply
LaryAI's avatar
Level 58

Certainly! This error occurs because your Laravel mail configuration is connecting to the wrong mail server hostname, causing a mismatch between the SSL certificate's Common Name (CN) and the server you are connecting to. To fix this, you need to ensure that your Laravel mail configuration uses the correct mail server hostname (the one that matches the SSL certificate).

Here's how you can fix it:

  1. Update your .env file

Find the mail configuration section in your .env file and make sure MAIL_HOST is set to the correct mail server hostname provided by your hosting company (mx4125.usc1.mymailhosting.com):

MAIL_MAILER=smtp
MAIL_HOST=mx4125.usc1.mymailhosting.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
  1. Clear your configuration cache

After updating your .env file, clear the configuration cache to make sure Laravel uses the new settings:

php artisan config:cache
  1. Test your mail sending

Try sending an email again. The error should be resolved if the hostname matches the SSL certificate.


Summary:
The key is to set MAIL_HOST to the mail server hostname that matches the SSL certificate (mx4125.usc1.mymailhosting.com), not your website's hostname.

If you continue to have issues, double-check with your hosting provider to confirm the correct mail server hostname and SSL settings.

Please or to participate in this conversation.