Is it possible to use view files for email content?

I know the SwiftMailer extension can do this but can it be done using the native mail() function?

So for example I currently have a $body variable that I populate with a whole load of text. I prefer if I could just put all text into its own file. To do this I will also need to pass it a model object.

So, can it be done and if so, how?

The SwiftMailer extension is a continuation of a previous extension by the same author not using SwiftMailer, so that’s possible.

Take a look at both. ;)

You can use the method render.

Create a widget for your email, and when you call email you can use:




$body= $this->render('viewName', array(), true);

mail(...);



The third parameter set to true will return the output of render, instead of echoing to the browser.