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@domain.com";

thanks for the help...

Chip

RitterKnight
  • 6,582
  • 14
  • 24
Chip Shank
  • 183
  • 6
  • 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 09 '17 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 09 '17 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 09 '17 at 20:24

1 Answers1

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.

Brad Bell
  • 67,440
  • 6
  • 73
  • 143