Email template with HTML: template not found

Hi,

I try to send an email using a HTML template but Kirby doesn’t find my template:
Error message Undefined variable: The email template "ads" cannot be found

I created a html template “ads”: site/templates/emails/ads.html.php

And this is my code to send the email:

$ad_date_formatted = date( "Y-m-d" , '1553558400');

  try {
    $kirby->email([
      'from'    => 'support@thewhale.cc',
      'replyTo'   => 'no-reply@thewhale.cc',
      'to'    => 'gillesvauvarin@gmail.com',
      'subject'   => 'The whale - Your Ad has been booked on',
      'template'  => 'ads',
      'data'  => [
          'ad_date_booked'  => date( "Y-m-d" , 1553558400 ),
          'ad_date_stop'    => date( "Y-m-d" ,  ( strtotime( $ad_date_formatted . ' - 5 days' ) ) ),
          'ad_id'       => 'id_xxxxxxxx',
          'ad_price'      => '$50',
          'ad_product_label'  => 'Sponsor Ads'
      ]
    ]);


  } catch ( Exception $error_mail ) {
    $email_catch_msg = 'Ad booking. Email sending failed: ' . $error_mail->getMessage();
      echo $email_catch_msg;
  }

Did I miss something or is it a bug?

The error message tells me that the text version is required as well…

Ok, I didn’t understand that both files were mandatory. I thought it was either one or the other.

Thank you Sonja.

If I want to use html, may I leave the text.php file empty and put my content only in the html.php?

I guess so, but maybe it makes sense to have the plain text version as well so that people who do not receive html email will still get something. It’s a fallback after all.

Yes, make sense :slight_smile: Thanks for your explanation :+1:

What do you both think? Should the text alternative be optional?

Yes. While it makes perfect sense, it is not really Kirby-like to leave me with no choice.

Agreed. Just checked and it seems optional by PHPMailer. So we shouldn’t make it required either.