Laminas mail smtp - Unable to resolve service to a factory

Hi everybody, I’m new to the Zend / Laminas world so I don’t kow if this is the right question to do.

I’m trying to make some testing with laminas sending e-mails via SMTP, but can’t make it work.

use Laminas\Mail\Message;
use Laminas\Mail\Transport\Smtp as SmtpTransport;
use Laminas\Mail\Transport\SmtpOptions;

$transport = new SmtpTransport();
$options   = new SmtpOptions(array(
    'name'              => '',
    'host'              => '',
    'port'              => 995,
    'connection_class'  => 'login',
    'connection_config' => array(
        'ssl' => 'SSL',
        'username' => '',
        'password' => 'my_password'

$message = new Message();

It was just like in the examples, but when i run it I get this error:

PHP Fatal error:  Uncaught Laminas\ServiceManager\Exception\ServiceNotFoundException:Unable to resolve service "Laminas\Mail\Protocol\Smtp\Auth\Login" to a factory; are you certain you provided it during configuration? in /ServiceManager.php:588

But I can’t find any reference anywhere that states that I have to define a factory for Smtp/Login.
And it is a Laminas internal class, I dont know what to do. Please, help!

I’d recommend you to confirm that you have a “Laminas\Mail” item in your modules.config.php. Probably the module declares the factory…

1 Like

Thanks for your help, do you mean in Laminas\Mail module? Or in my laminas MVC app config?

I just discovered the problem is related to the Smtp Auth since sending my message with FileTransport or Sendmail does work!

In your Laminas MVC config/modules.config.php, like here: passwordless-auth-example/modules.config.php at master · renanliberato/passwordless-auth-example · GitHub

1 Like

Thank you! Problem solved!

1 Like