Laminas Mail with SMTP not sending mail on development server (but does send on production server)

There is a lot on the web, but i didn’t solve it yet.

I am using laminas mail with an SMTP connection to send mail, this works fine on production server, but for testing purposed i also want to use it on my developmentserver. For some reason it does not work there, with the same settings (see below)

$options   = new SmtpOptions(array(
                'name'              => 'maintenanceplus.nl',
                'host'              => 'mail.antagonist.nl',
                'port'              => 587,
                'connection_class'  => 'login',
                'connection_config' => array(
                    'username' => '****',
                    'password' => '****',
                    'ssl' => 'tls'
                ),
            ));

I am using Apache2 with PHP8.2 on a windows machine.

Error Laminas\Mail\Protocol\Exception\RuntimeException: Unable to connect via TLS

[php:warn] [pid 27056:tid 1220] [client ::1:58629] PHP Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:0A000086:SSL routines::certificate verify failed in D:\OneDrive\PHP_projecten\Maintenance.nl\vendor\laminas\laminas-mail\src\Protocol\Smtp.php on line 297, referer: http://maintenance.localhost/user/registreren

And without ssl/tls option

Laminas\Mail\Protocol\Exception\RuntimeException: 5.5.1 Invalid command

If the remote mail server is running TLS, then turning TLS off locally is never going to work. If you can communicate with the remote server on a different port that’s not running TLS, then you might have some luck but everything will be sent in the clear.

The error message clearly states that the SSL cert could not be verified - this is possibly due to differences between the ca certificate stores on your local machine and the production machine.

It is possible to turn off cert validation, but not advisable:

Please keep in mind that laminas-mail is abandoned.

Yes, i saw after composer update. Symfony mailer is recommended if i’m correct. Is there somewhere an example how to integrate it into Laminas?

You can give it a try to dot-mail
Which is a wrapper on top of symfony mail ready to be used in a middleware
https://packagist.org/packages/dotkernel/dot-mail

1 Like

Thanks All! I Switched to PHPMailer and with (extra) parameters below that does work!

$mail->SMTPOptions = array(
            'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        );