Rendering Mail Template as PDF and attaching it to same email

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.
octobermail
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.

Maybe this will help you

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

I can’t invoke App there within the theme, should I call the App::make(‘twig.environment.mailer’) somewhere earlier in startup?

appcomponent

Perhaps I’m just not referencing it correctly? File structure is Saint-Anthony > themes > saint-anthony-cares-theme > views >mail > frontend.

I think my October project is setup in Saint-Anthony in the top of the hierarchy, should it be setup in the theme? Could that be what’s interfering?

I tried this and it works


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

}

Same issue as before, App has no effect.

Edit: Nevermind, I had to remove “use App;”

Now I’m having issues because I never instantiated $dompdf, hold on.

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.

Sounds like the CSS is missing from the DOMPDF export contents.

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.