Email template with HTML: template not found


#1

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?


Sending an email with html-body content
#2

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


#3

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

Thank you Sonja.


#4

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


#5

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.


#6

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


#7

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


#8

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


#9

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


#10