Multiple E-Mail Transport?

I maintain one site that has a) a contact form and b) a newsletter sign-up form using the Uniform plugin.

For the contact form, I’d like to use as sender the email address info@, but for the newsletter I’d like the sender to be newsletter@.

Looking at the documentation for email transport setup, I only see a single SMTP option, which doesn’t work as both email addresses use different authentication.

Is this impossible then?

You don’t have to set transport settings in the config, you can do this on a per use case basis. I would expect that if you set a default transport array in your config, that you can also override this with local settings when calling $kirby->email().

1 Like

What happens when you don’t set any transport configuration anywhere?

Then Kirby will try to send via sendmail()

I guess then the question goes more towards @mzur whether I can set these config on the Uniform emailAction() :thinking:

The Uniform documentation states:

The email action accepts the same options than the email function of Kirby.

But last I tried to use multiple senders or similar, that didn’t actually work as described in the Kirby documentation.

But have you actually tried to set the transport options in the email action?

1 Like

After playing around with it a bit more, I came up with a solution that I like and that solves my issues

  • Uses different transport configurations for contact and newsletter forms
  • Works with Uniform
  • Keeps the authentication information in the config

config.php

    'smtp' => [
        'info' => [
            'type' => 'smtp',
            'host' => 'smtp.example.com',
            'port' => 587,
            'security' => true,
            'auth' => true,
            'username' => 'info@example.com',
            'password' => 'TopSneaky',
        ],
        'newsletter' => [
            'type' => 'smtp',
            'host' => 'smtp.example.com',
            'port' => 587,
            'security' => true,
            'auth' => true,
            'username' => 'newsletter@example.com',
            'password' => 'TopSneaky',
        ]
    ],

Contact Controller

$form->emailAction([
        'to' => iconv("UTF-8", "ISO-8859-1", $form->data('email')),
        'from' => 'info@example.com',
        'fromName' => iconv("UTF-8", "ISO-8859-1", 'Supports öäü'),
        'replyTo' => 'info@example.com',
        'replyToName' => iconv("UTF-8", "ISO-8859-1", 'Supports öäü'),
        'subject' => 'Subject Line',
        'template' => 'contact',
        'transport' => option('smtp.info')
    ])

Newsletter Controller

$form->emailAction([
        'to' => iconv("UTF-8", "ISO-8859-1", $form->data('email')),
        'from' => 'newsletter@example.com',
        'fromName' => iconv("UTF-8", "ISO-8859-1", 'Supports öäü'),
        'replyTo' => 'newsletter@example.com',
        'replyToName' => iconv("UTF-8", "ISO-8859-1", 'Supports öäü'),
        'subject' => 'Subject Line',
        'template' => 'newsletter',
        'transport' => option('smtp.newsletter')
    ])

Thanks for all the hints and I hope this will help someone else in the future! :slightly_smiling_face:

2 Likes