I’ve got an existing website with a large employment application, the client we built it for wants us to send the form submissions as PDFs. The dev that built the form out is no longer here so I can’t ask him questions about this. For reference, its October 2 and PHP 7.4, its a few years old.
Here is the code I’ve been working on, the pre-existing mail functionality is all working locally.
However, when trying to access the template using the Mail::render function I get that the view “frontend::job.application-full” does not exist or can’t be found. (FYI I have no idea if the Mail::render function really exists I can’t actually find it in October’s Docs, I’ve tried about seven different options here that have all given me that same error)
The path to the templates is Themes>[theme]>views>mail>frontend>job.application.htm.
I have tried registering them as views but I get the same error. Is there some sort of composer command I need to run? Why are they working just fine with Mail::queue? I’ve seen discussion about registering them in a theme.php file, but this theme doesn’t have one. Any help would be greatly appreciated, I’m sure its simple I’m just at my wits end.
use App;
use System\Models\MailTemplate;
$template = MailTemplate::where('code','frontend::job.application-full')->first();
$twig = App::make('twig.environment.mailer');
$templateTwig = $twig->createTemplate($template->content_html);
$html = $templateTwig->render(['key' => 'value']); #here you can enter your variables
function onApplicationSubmit() {
$template = \System\Models\MailTemplate::where('code','frontend::job.application-full')->first();
$twig = App::make('twig.environment.mailer');
$templateTwig = $twig->createTemplate($template->content_html);
$html = $templateTwig->render(['key' => 'value']); #here you can enter your variables
}
Okay so it is working and sending the pdf attached as an email, however it looks nothing like the email template, I don’t think its rendering the html at all. Its just a giant plaintext string.
It appears to be because after the twig rendering its missing its html tags and is just markdown, I’ll see if I can go from markdown to pdf instead.
I managed to figure it out, the template was written in markdown but had html templating, so I had to add an additional step rendering the markdown as html before saving it as a pdf.