Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Email templating in PHP
New on LowEndTalk? Please Register and read our Community Rules.

Email templating in PHP

Building new app and looking for existing libraries for parsing html email templates to send email via PHP.

Example of HTML template.html:

Hello {{ user }},

Today is {{ date }}, a wonderful day to visit {{ url }}.

Now for PHP part I assume it would something like this (pseudo):

data['user'] = 'Name';
data['date'] = date();
data['url'] = 'lowendtalk.com';

SendEmail('template.html', $data[]);

Anyone knows library for "SendEmail" parser?

Comments

  • Use twig/twig, render the template separately and then use your typical email sending functions (PHPMailer, nette/email and the likes) to send the email.

    Thanked by 1yoursunny
  • FranciscoFrancisco Top Provider
    edited September 14

    are you using an MVC? Most have a way to output their view/blades into a variable.

    You could then just feed that to your mail sending function as the body.

    Francisco

    BuyVM - Free DirectAdmin, Softaculous, & Blesta! / Anycast Support! / Windows 2008, 2012, & 2016! / Unmetered Bandwidth!
    BuyShared - Shared & Reseller Hosting / cPanel + Softaculous + CloudLinux / Pure SSD! / Free Dedicated IP Address
  • why not this one:

    $to = '[email protected]';
    $subject = 'Daily greeting';
    $headers = "From: Somebody <[email protected]>" . "\r\n";
    $user - 'Name';
    $date = date();
    $url = 'lowendtalk.com';
    
    $email = "Hello $user,
    
    Today is $date, a wonderful day to visit $url."
    
    mail($to,$subject,$email,$headers);
    
    Thanked by 1TheKiller

    🌈 A simple uptime dashboard using UptimeRobot API https://upy.duo.ovh
    🌈 BuyVM, GreenCloudVPS, Gullo, Hetzner, HostHatch, InceptionHosting, LetBox, MaxKVM, MrVM, VirMach.

  • @stevewatson301 said:
    Use twig/twig, render the template separately and then use your typical email sending functions (PHPMailer, nette/email and the likes) to send the email.

    Hi {{ user.first_name }},
    

    moment

  • Looks like Mustache syntax - https://github.com/bobthecow/mustache.php

  • varwwwvarwww Member
    edited September 14
    composer require mustache/mustache
    

    Script: https://pastebin.com/Dhbw74HD

    Thanked by 1LTniger
  • @varwww said:

    composer require mustache/mustache
    

    Script: https://pastebin.com/Dhbw74HD

    This is exactly what I need! Clean and simple. Once again, LET crowd strikes and delivers. Thank you.

  • vovlervovler Member
    edited September 14

    Just hit it with

    $email = str_replace("{first_name}", "Pony", $email);
    

    No need for third party libraries.

    ;)

    "They said it's RAID 5" - geekypixal

Sign In or Register to comment.