I’m trying to send and email using Kirby’s built-in email function, but the email body, which contains some HTML, is rendered as plain text by default, it is fine but unfortunately it doesn’t cover my case. Is there a way or just an option to set the content-type to text/html?
This is just an example of a possible option to achieve the goal:
$email = new Email(array(
'to' => 'mail@example.com',
'from' => 'john@doe.com',
'subject' => 'Yay, Kirby sends mails',
'body' => 'Hey, this is a <strong>test email!</strong>'
'options' => array(
'isHtml' => true
)
));
The toolkit docs say you can create your own adapter. I believe this is the only way to bypass the default header. You can try copying the default adapter and changing the header in the new service.
Now, I’m not sure if this works when added in a plugin, to a page controller, or if it has to be added to the core e-mail file. The docs don’t specify. Perhaps @bastianallgeier or someone else can specify.
To specify the service try
$email = new Email(array(
'to' => 'mail@example.com',
'from' => 'john@doe.com',
'service' => 'html_email',
'subject' => 'Yay, Kirby sends mails',
'body' => 'Hey, this is a test email!'
));
if($email->send()) {
echo 'The email has been sent';
} else {
echo $email->error()->message();
}
The @Luke solution works fine. Put the content of the first snippet of his post in a file and move it in your Kirby ‘plugins’ folder. To use it, follow the second snippet.