2

This is probably a newby question, but, I am just trying to add a basic email send test and my twig page does not like the dollar signs. Is EmailModel built-in to craft or is there a plugin I need?

I am just trying to add this code to a basically empty twig page:

$email = new EmailModel();
$email->subject = "Thanks!";
$email->htmlBody = "<h1>Congratulations!</h1";
$email->htmlBody .= "<p>Hello World</p>";
$email->fromEmail = "[email protected]";

thanks for the help...

Chip

3
  • 1
    You're adding PHP to a Twig page? Unless I'm missing something, that fundamentally doesn't make sense. Can you show us how you've added this to your Twig code?
    – Lindsey D
    Apr 9, 2017 at 15:06
  • I am transitioning from a C#/.net background to a CraftCMS/Twig/PHP platform, so, I recognized that this didn't seem to make sense, but, I couldn't find a way to easily integrate an email process into my Craft CMS site (built of twig pages) and this was the only code I have found so far. What is the best way to do this: When a user hits a button on the site, I want a pdf file to be attached and emailed to an email address that was typed into a text box on that page.
    – Chip Shank
    Apr 9, 2017 at 18:03
  • You probably answered the question that I brought up. I will ask my more general question as a new question. Thanks.
    – Chip Shank
    Apr 9, 2017 at 20:24

1 Answer 1

2

You can't use PHP in a Twig template.

A plugin Craft plugin would be the easiest way to pull off what you're looking for. I've added an answer to your other related question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.