Code: Select all
<?php
$res = mysql_query("SELECT `firstname`, `lastname`, `username` FROM `users` WHERE `id` = 1");
$arr = mysql_fetch_assoc($res);
$text = 'hello, ' . $arr['firstname'] . '
Your last name is ' . $arr['lastname'] . '
and your username is ' . $arr['username'];
//mail hereI'd made a custom mailing class to handle the tags and replacing. I'd just pass the tags in like this:
Code: Select all
<?php
$res = mysql_query("SELECT `firstname`, `lastname`, `username` FROM `users` WHERE `id` = 1");
$arr = mysql_fetch_assoc($res);
$email->send('sample-email', array('{firsntame}', '{lastname}', '{username}'), array($arr['firstname'], $arr['lastname'], $arr['username']);So, I evolved a bit. I'd use tags that were the same names as the fields in the database and pass in the corresponding table names to my function, so my emailing class could do the querying for whatever tags were in there, like so:
Code: Select all
<?php
$email->send('sample-email', $toAddress, array('users' => array('firstname', 'lastname', 'username')));so here's my new idea
I make tags like this in the emails {users|firstname}, {users|lastname}, {users|email}
This way I can match everything between {} as tags, then explode on the | and have the table name and field name to query for the value! I could even make special tags for POST, GET, COOKIE, and config, such as {.post|fieldname} {.get|fieldname} {.cookie|cookiename} and {.config|varname}. Then I could pass in special formatted values to the function and use them only when I have to.
In the end I could send an email like this without having to query for any data:
Code: Select all
Hi {users|firstname},
Your lastname is: {users|lastname}
Your username is: {users|username}
Please login at {.config|SITE_URL}login.php
You have {messages|num_messages} awaiting!
{.config|emailsig}