STARTTLS - config for email transport

Hello everyone,

I am building a simple contact from, but can’t create a connection to the email server. I am wondering if my email transport is configured correctly.

The emails should be sent via Port 587 and uses SMTP over STARTTLS. According to the docs `port 587` is the default anyways and modern servers should handle `tsl/ssl` automatically. But no luck for me :smiling_face_with_tear:

This is the config:

return [
    'ready' => function () {
        return [
            'email' => [
                'presets' => [
                    'contact-form' => [
                        'from'  => 'noreply@domain.com',
                        'to'    => 'contact@domain.com',
                    ]
                ],
                'transport' => [
                    'type' => 'smtp',
                    'host' => env('MAIL_HOSTNAME'),
                    'port' => 587,
                    'security' => true,
                    'auth' => true,
                    'username' => env('MAIL_USER'),
                    'password' => env('MAIL_PASSWORD')
                ],
            ],
        ];
    },
];

But when I try to submit the form it throws this error:

SMTP Error: Could not connect to SMTP host. Failed to connect to server

So, I am wondering if I am missing some config settings? I have also tested this with another mail server with the same settings but on port 465. There it worked.

Any Ideas? Any help appreciated :slight_smile:

Ok, so if I understand this correctly, then Port 587 always uses STARTTLS. And since its the default setting in kirby, my config should actually be correct :thinking:

Never mind, my env variables where wrongly set :melting_face: