I've been struggling to make this work within a plugin. I have a html file in my templates folder called _email.html. I try to load it in my plugin but then I get an error. This is my code:
Craft::$app->mailer->compose('_email.html', ['body' => $emailBody]) ->setFrom($fromMail) ->setTo($toMail) ->setSubject($subject) ->send();
The problem is that the Yii mailer is looking in the vendor folder instead of the templates folder.
This is the error I get:
The view file does not exist: /Applications/MAMP/htdocs/project/vendor/craftcms/cms/src/mail/_email
Even when I try going back to the templates folder it doesn't seem to work and I get the following error:
The view file does not exist: /Applications/MAMP/htdocs/project/vendor/craftcms/cms/src/mail/../../../../../../templates/_email
I found out that if I copy and paste the contents of the _email.html file and do the following it does work, but this obviously is a pretty bad workaround