I want to send an email using crafts mailer in Craft 4. I've seen this post: How to send email from Craft 3 custom plugin?
But now I need this adapted for craft 4. Unfortunately I did not succeed so much.
I think something like this:
$mail = Craft::$app->mailer;
$mail->template = "My email template. How to use placeholders?";
$mail->send($message); // how do I set up that message?
// where can I set the recipient address?
Links: https://docs.craftcms.com/api/v4/craft-mail-mailer.html#public-methods
I want to use the settings I have set in the CP:
I would be very thankful for an example, as the Craft 4 documentation is a bit to sparse for somebody like me .

The link here: https://docs.craftcms.com/api/v4/craft-mail-mailer.html#public-methods lists some but I still don't get how it works... :s
- $messageSubject is just a string, right?
- What is the
– Merc Feb 27 '23 at 13:50View::TEMPLATE_MODE_SITEpart?if you no need to render from twig template you can just put your html code inside the $html variable.
– aodihis Feb 28 '23 at 03:21$view = Craft::$app->getView();with this error:\"modules\\commentmodule\\controllers\\View\" not found",Is this related to: https://verbb.io/blog/everything-you-need-to-know-about-modules#templates > so I need to register views in my controller first? (I will try and report back here, if I find a solution :)) Sorry for all the beginners questions :S – Merc Feb 28 '23 at 09:17/modules/commentmodule/CommentModule.php.I have
/modules/commentmodule/templates/emails/mail.twigand I try to render it$html = Craft::$app->getView()->renderTemplate('commentmodule/emails/mail.twig', $variables);– but then it will fail withTemplate could not be found. :(And I try to render that template within
– Merc Feb 28 '23 at 09:37modules/commentmodule/controllers/MailController.php