Search code examples
phphtmlcsstwigphpmailer

Working with Twig and PHPMailer


I am developing a web that work with Twig and PHPMailer. When the system send a email, I want that email's body to be in HTML. I must show data in email's body. I have the file personal.php that pass data to file personal.html by Twig

$twig->display('Personal.html',array(
    "text" => $text,
    "lenguaje" => substr($lang, 0, 2)
    ));

How I do to pass the HTML file with Twig?. When I pass data I do

$body = '<div>
            <p>'.$this->text['pass_recov_body'].'</p>
            <p><strong>'.$this->text['date_user'].'</strong></p>
            <p><strong>'.$this->text['user'].': </strong>'. $data['txtRecEmail'] . '</p>
            <p><strong>'.$this->text['password'].': </strong>'. $data['txtUsrPass'] . '</p>
        </div>
    ';


    $this->msgHTML($body);

but now I want pass a HTML file with CSS


Solution

  • Use render() instead of display()

    $this->msgHTML($twig->render('Personal.html',array(
        "text" => $text,
        "lenguaje" => substr($lang, 0, 2)
    )));