I have a responsive email template in a php file and trying to send it with PHP mailer with no success. My code looks like this.
$m = new PHPMailer;
// endof debug
$m->Subject = 'Welcome to Efie';
$m->FromName="Contact Form Efie";
echo '<p class="errors bg-success text-success">Email Received</p>';
The problem you're seeing is that
file_get_contents literally gets the contents of the file, it does not run it as a PHP script. There are several ways to solve this.
include the file while assigning it to a variable, like this:
$body = include 'functions/register-email.php'; $m->msgHTML($body, dirname(__FILE__));
The problem with this approach is that you can't just have content sitting in the file, you need to
return it as a value, so your template would be something like:
<?php $text = <<<EOT <html> <body> <h1>$headline</h1> </body> </html> EOT; return $text;
An easier approach is to use output buffering, which makes the template file simpler:
ob_start(); include 'functions/register-email.php'; $body = ob_get_contents(); ob_end_clean(); $m->msgHTML($body, dirname(__FILE__));
and the template would be simply:
<html> <body> <h1><?php echo $headline; ?></h1> </body> </html>
Either way, the template file will have access to your local variables and interpolation will work.
There are other options such as using
eval, but it's inefficient and easy to
do things wrong.
For working with Zurb, you really need a CSS inliner such as emogrifier to post-process your rendered template, otherwise things will fall apart in gmail and other low-quality mail clients.
FYI, this stack - Zurb templates, Smarty, emogrifier, PHPMailer - is exactly what's used in smartmessages.net, which I built.