Sending Emails
Third-party services
Usually, your host's SMTP server is very limited in sending emails. In addition, you will have a very high risk of your email landing in your members' spam folders since certification of authenticity does not back it up.
Unless you have a very good reason not to, I suggest using any third-party service to send emails you feel comfortable using. Their services vary greatly, and their pricing is based on the email volume.
Suggestions, some have their own Kirby CMS plugins for additional functionality:
My recommendation would be to use a .env
file to store your credentials and use the ready
-hook to apply the values once the dotenv plugin has them loaded.
<?php
return [
'auth' => [
'methods' => ['code', 'magic-link'],
'challenge' => [
'email' => [
'from' => 'myverifiedsender@mydomain.com',
'fromName' => 'My Name',
]
]
],
'ready' => function () {
return [
'email' => [
'transport' => [
'type' => 'smtp',
'host' => 'smtp.postmarkapp.com',
'port' => 587,
'security' => true,
'auth' => true,
'username' => env('POSTMARK_USERNAME'),
'password' => env('POSTMARK_PASSWORD'),
],
],
];
},
];
In the case of Postmark, you will need to create a SMTP configuration for your broadcast channel.
Testing Emails
You could use tools like the free Mailhog or paid ones like HELO or HERD Pro to catch emails sent using your local SMTP server. If you need to test emails on an online staging server, consider Mailtrap or similar alternatives.
The configuration for all of them is very similar, only differing in set config values.
<?php
return [
// https://getkirby.com/docs/cookbook/forms/using-mailhog-for-email-testing
// OSX: brew install mailhog; brew services start mailhog
// BROWSER: http://localhost:8025/
'email' => [
'transport' => [
'type' => 'smtp',
'host' => 'localhost',
'port' => 1025,
'security' => false,
],
],
// other options
];
FavIcon and BIMI
You can do two things to get an image displayed for your email sender in the customer's email clients.
The simplest is having a favicon.ico
file at the server's public HTML root matching the same domain.
Like emails from no-reply@example.com
=> https://example.com/favicon.ico
But the support for that is basic at best, and email clients like Gmail switched to certified BIMI SVG logos a while ago. That will require you to set up SPF, DKIM and DMARC, and a 3rd party service will make this easier. To gain full email client support, you will need to get your logo certified as a verified mark, as explained by the BIMI Group.
Creating Emails
While you could create emails with plain HTML, certain, sometimes unexpected limitations exist. My suggestion would be to use MJML (a plugin for VSCode) in combination with inlined PHP to avoid most of the issues you do not even know could happen yet.
There are also online tools, like Litmus, available to test your emails on various email clients and operating systems. However, these usually only have paid tiers or short trials.
<mjml>
<mj-head>...<mj-head>
<mj-body>
<mj-include path="./logo.mjml"/>
<mj-section><mj-column>
<mj-text><?= $text ?></mj-text>
</mj-column></mj-section>
<mj-include path="./footer.mjml"/>
</mj-body>
</mjml>
{
"scripts": {
"mjml": "mjml site/mjml/email.mjml -o site/templates/emails/email.html.php --config.validationLevel skip"
},
}