<p>You can't use <a href="https://craftcms.stackexchange.com/questions/722/can-we-use-php-in-our-templates-instead-of-twig">PHP in a Twig template</a>.</p>

<p>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 <a href="https://craftcms.stackexchange.com/questions/19861/what-is-the-best-way-to-generate-email-messages-with-attachments-from-twig-files">related question</a>.</p>

CC BY-SA 3.0
2017-04-09T23:12:59.683Z
2017-04-09T23:12:59.683Z
Brad Bell
<p>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?</p>

<p>I am just trying to add this code to a basically empty twig page:</p>

<pre><code>$email = new EmailModel();
$email-&gt;subject = "Thanks!";
$email-&gt;htmlBody = "&lt;h1&gt;Congratulations!&lt;/h1";
$email-&gt;htmlBody .= "&lt;p&gt;Hello World&lt;/p&gt;";
$email-&gt;fromEmail = "email@domain.com";
</code></pre>

<p>thanks for the help...</p>

<p>Chip</p>

CC BY-SA 3.0
2017-04-09T15:06:36.507Z
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
CC BY-SA 3.0
2017-04-09T18:03:07.117Z
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
CC BY-SA 3.0
2017-04-09T20:24:21.857Z
You probably answered the question that I brought up.  I will ask my more general question as a new question. Thanks.
Chip Shank
<emails>
EmailModel - Unexpected character "$"?
# EmailModel - Unexpected character "$"?

(Asked by: username_0 on 2017-04-09)

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 = "Congratulations!htmlBody .= "Hello World";
$email->fromEmail = "email@domain.com";

thanks for the help...
Chip

**Tags:** emails
> **Comments:**
> **username_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?  
> **username_0**: 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.  
> **username_0**: You probably answered the question that I brought up.  I will ask my more general question as a new question. Thanks.  

---

## 1 answers

### Answer by username_2 on 2017-04-09. Score: 2 | Accepted answer

You can't use [PHP in a Twig template](https://craftcms.stackexchange.com/questions/722/can-we-use-php-in-our-templates-instead-of-twig).

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](https://craftcms.stackexchange.com/questions/19861/what-is-the-best-way-to-generate-email-messages-with-attachments-from-twig-files).


---

