Vote count:
0
I want to create a simple PHP Class for sending basic HTML emails in PHP. It is something I have to do often in a lot of my projects and I find myself always reproducing the same code to allow me to create the email template and then setting up an array of key/values to parse my email template HTML with variables from my PHP.
I thought it might be useful for me to create a simple PHP Class that could do this same thing and speed things up by being flexible.
So here is some basic example HTML for the Email body.... Variables that will need to be replaced in the template with values from PHP variables are wrapped with {{var_name}}
<html>
<body>
<h1>Account Details</h1>
<p>Thank you for registering on our site, your account details are as follows:<br>
Username: {{username}}<br>
Password: {{password}} </p>
</body>
</html>
In the above example there are 2 variables that need to be populated. {{username}} and {{password}}
I would like to be able to simply pass my Class function a PHP Array where the Array key is the variable name and the value is the value that would be populated in my email template.
So something like this would be passed into my method/function that parses the email template....
$emailValues = array(
'username' => 'My username value here',
'password' => 'My password value here'
);
$emailHtml = new EmailParser($emailValues);
Now I could simply create my email and pass in $emailHtml which would have the email template with the variable populated with the correct values and this variable $emailHtml could be set as the Emails Body.
I am curious how I could best achieve this?
Simple PHP Template Parsing
Aucun commentaire:
Enregistrer un commentaire