Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send Emails with CakePHP 4

I want to send an email with CakePHP 4. In app_local.php i have following entry

    'EmailTransport' => [
    'default' => [
        'host' => 'smtp.XXX.de',
        'port' => 25,
        'username' => null,
        'password' => null,
        'client' => null,
        'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
    ],
],

If i try to send an email with following Code

            $mailer = new Mailer('default');
            $mailer->setFrom(['[email protected]' => 'Willi'])
                ->setTo('[email protected]')
                ->setSubject('About')
                ->deliver('blablabla');

i got following ErrorMessage

Could not send email: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

Why is Cake trying to use Mailserver at localhost??? Where is my error? ;-)

like image 347
majamuel Avatar asked Apr 30 '26 22:04

majamuel


1 Answers

you are missing: 'className' => 'Smtp'.

'EmailTransport' => [
    'default' => [
 'className' => 'Smtp',
        'host' => 'smtp.XXX.de',
        'port' => 25,
        'username' => null,
        'password' => null,
        'client' => null,
        'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
    ],
],
like image 68
KenDzz Avatar answered May 02 '26 13:05

KenDzz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!