Menu

#52 2 new method: AddTemplate & AddLinkToWebBrowser

wont-fix
nobody
None
5
2012-12-28
2009-12-11
No

I use at work a custom version of PHPMailer, and if it can help anyone else...

AddTemplate allows to apply a template to the mail. The first parameter is the url to the template, the second is an array of variables that will be replace in the template if you want to custom the mail for every receiver.

AddLinkToWebBrowser put a link in the bottom of the mail, typically a link "if you don't see this email, please click here"

/*
* Adds a template for the html body
* EX :
* $template : mailing.tpl
* $pas_params : array('%contenu%'=>'contenu du mail', '%tel%'=>'numero de téléphone')
/
function AddTemplate($template, $pas_params)
{
if (!is_file($template))
{
$this->SetError($this->Lang('template_not_found'));
return false;
}
else
{
$this->Body = str_replace(array_keys($pas_params),
array_values($pas_params),
file_get_contents($template)
);

        return true;
    }
}

/**
 * Adds a link to html page if the webuser can't see the mail properly
 * EX :
 * $description : 'Cliquer ici si vous ne visualisez pas correctement cet e-mail'
 * $lien : 'http://www.test.com/emailing.php?email=noname@toto.com'
 */
function AddLinkToWebBrowser($description, $lien)
{
    // le mail doit être en HTML
    if ($this->ContentType != 'text/html')
    {
        $this->SetError($this->Lang('wrong_content_type'));
        return false;
    }
    else
    {
        // le lien doit être absolu
        if (mb_substr(mb_strtolower($lien), 0, 7) != 'http://')
        {
            $this->SetError($this->Lang('need_absolute_url'));
            return false;
        }
        else
        {
            $this->Body = str_replace('</body>', 
                                        '<br /><br /><div style="text-align:center;"><a href="'.$lien.'" target="_blank">'.$description.'</a></div></body>', 
                                        $this->Body
                                        );

            return true;
        }
    }
}

Discussion

  • Marcus Bointon

    Marcus Bointon - 2012-12-28
    • status: open --> wont-fix
    • milestone: --> Next_Release_(example)
     
  • Marcus Bointon

    Marcus Bointon - 2012-12-28

    Merci, but there are so many good PHP templating systems that there's really no point in inventing a new one and having to deal with all its security issues. Smarty and Twig are both great for email.
    Adding a link like that is very application-specific, and is already trivial to do via the HTML source you provide in your message.

     

Log in to post a comment.