Use two different email transport with authentication in the same project?

Hi,

In a website project, I’ve got two different forms which send an email when the user submit the form.

For these two forms, I would like to use two different email transport authentication.

If the form is submitted from page = A use :

'email' => [
		'transport' => [
			'type' => 'smtp',
			'host' => 'smtp.xxx.com',
			'port' => 587,
			'security' => true,
			'auth' => true,
			'username' => 'toto@website.com',
			'password' => '1234',
		],
	],

If the form is submitted from page = B use :

'email' => [
		'transport' => [
			'type' => 'smtp',
			'host' => 'smtp.xxx.com',
			'port' => 587,
			'security' => true,
			'auth' => true,
			'username' => 'titi@website.com',
			'password' => '5678',
		],
	],

Is there a solution to achieve this?

You can define the transport right where you send the email, transport would be an additional key next to to, from etc.

Something like this?

$kirby->email([
	'template' => 'support_wowa',
	'from' => $page->f_email_email()->toString(),
	'fromName' => $site->title()->toString(),
	'to' => $page->f_email_email()->toString(),
	'subject' => $page->f_email_subject()->toString(),
        'transport' => [
                'type' => 'smtp',
	        'host' => 'smtp.xxx.com',
		'port' => 587,
		'security' => true,
		'auth' => true,
		'username' => 'titi@website.com',
		'password' => '5678',
        ],
	'data' => [
		'first_name' => esc($data['f_first_name']),
		'last_name' => esc($data['f_last_name']),
		'email' => esc($data['f_email']),
		'message' => get('message'),
	],
]);

Looks good, does it not work?

Yes it works :slight_smile:
Thanks Sonja