Just wondering if it would acctually be possible to set up template files for emails? I am using Smarty and PHPMailer (both latest versions)

Here is my idea, but I'm not quite sure where to go next

Template file

Hello {$user}
Please click on this link to activate your account:

{$link}

Thank you, if you have any questions or this link does not work,
please send an email with your question to {$email}
or go to the contact page ( {$contact_link} )

See you on the boards soon,
camowel
<?php

// Set up the two classes
require_once('config.php'); // $site
require_once('mailsetup.php'); // $mail
require_once('smartysetup.php'); // $smarty

function smartymail($file) {
  // somehow get the smarty file parsed and into the mail's body
}

$smarty->assign('link', $site['root'].'/activate.php?ID='.urlencode($ID));
$smarty->assign('contact_link', 'contact.php?s='.urlencode('Activation Email'));
$smarty->assign('user', $username);
$smarty->assign('email', $site['admin_mail']);

$mail->Subject = 'Please activate your account';
$mail->AltBody = smartymail('/mail/activate_account.tpl');
$mail->Body = nl2br($mail->AltBody);

$mail->Send();

If anyone thinks its possible please post your ideas for the smartymail() function, if you have an idea different from mine for making this work it would also be greatly appreciated!

Thanks for reading!

    I'm not too sure about the $smarty object and what assign() does, but you could use keywords instead of filling in variables, i.e.

    Hello {USER}
    Please click on this link to activate your account:
    
    {LINK}
    ...

    and then use a simple [man]str_replace/man to replace {USER} with the approrpriate $smarty or variable reference.

    As I said, I'm not familiary with Smarty, so you'll have to bear with me on this one! Sorry.

      I use exactly what bradgrafelman does for email templates, but if you are using smarty the $smarty->fetch('template.tpl') will bring back the template parsed into a string, so you wouldn't even need to add your custom file, you can use that directly and assign it to the html part.

        Wow, wasn't expecting it to be that simple 🙂

        I guess I should have searched the smarty site a bit more to find out about different functions like that

        Thanks for the replies! 🙂

          wow thanks again 😃

          EDIT: I just downloaded the chm file, its amazing 😃

            The $smarty->fetch thing worked great!

            Now I know I need to work on my smarty setup, as I just mailed myself a smarty error 🙂

            Thanks again for helping!

              Write a Reply...