Sending emails
Kirby has a built-in email engine, which can be used to send notifications to your users, replies to filled in contact forms and more.
It's highly recommended to add a transport configuration to increase the chances that your emails will be accepted and received by the recipients.
Send an email
Simple
With custom sender name
With multiple recipients:
Formats
Plain Text
HTML & Plain Text
Directly set body without template
Personalize emails to multiple users
Attachments
Check if email is sent successfully
Presets
If you keep using the same options over and over in your controllers, models or elsewhere, setting up email presets in your config file can help you to keep your code lean and clean:
You can then call the email method and pass the preset name as first argument and any options you want to add/customize for this specific email as second argument:
Transport configuration
Many web hosts impose strict limits on the number of emails the PHP mail feature can send, which can result in delays or non-delivery of your emails. In addition, because these emails are sent from your web server, the server's reputation has a significant impact on email deliverability. If your web server has a poor reputation, your emails may end up in recipients' spam folders or be blocked altogether.
To avoid this, it is recommended to add an email transport configuration, most commonly an SMTP server:
Read about more details/options of the email.transport
config option.
Access PHPMailer
You can get access to the underlying PHPMailer instance via the beforeSend
callback:
It can be useful to add embedded images:
The beforeSend
callback can also be added as preset.