majamuel
majamuel

Reputation: 31

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? ;-)

Upvotes: 3

Views: 2249

Answers (1)

KenDzz
KenDzz

Reputation: 49

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),
    ],
],

Upvotes: 1

Related Questions