3

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(['willi@test.de' => 'Willi'])
                ->setTo('wutz@test.de')
                ->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? ;-)

majamuel
  • 31
  • 4
  • Its fairly odd that your mail server would in this day and age be using port 25 and a passwordless access. – RiggsFolly Mar 02 '21 at 15:49
  • It´s an internal testsystem, just for checking if anything would work... – majamuel Mar 02 '21 at 15:51
  • Do you also have an `Email` section in that file, separate from `EmailTransport`? – Greg Schmidt Mar 02 '21 at 20:03
  • @Greg Schmidt Yes, the email section is here... `'Email' => [ 'default' => [ 'transport' => 'default', 'from' => 'you@localhost', /* * Will by default be set to config value of App.encoding, if that exists otherwise to UTF-8. */ //'charset' => 'utf-8', //'headerCharset' => 'utf-8', ], ], ` – majamuel Mar 03 '21 at 06:53
  • Finally i found it.... I use the cake app skeleton and i think the config for email transport is not as it should be for cake 4... In Configuration you have to tell the classname how mails should be transported.... mail / smtp / debug In app_local i now have added `'EmailTransport' => [ 'default' => [ 'className' => 'Smtp', ` – majamuel Mar 03 '21 at 07:05

1 Answers1

1

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),
    ],
],
KenDzz
  • 39
  • 2
  • 7
  • 1
    Please provide additional details in your answer. As it's currently written, it's hard to understand your solution. – Community Sep 05 '21 at 13:31