In this chapter, you will learn how to add extra functionality to your phpList installation by "hacking" the source code. Unlike the advanced features previously covered, none of the hacks covered in this chapter are officially supported by phpList and may not work in future versions. Instead of teaching you how to implement specific features, this chapter is aimed more at teaching the basic methods behind adding functionality to phpList by either making direct code changes or implementing pre-packaged, community-developed hacks.
We will cover the following hacks:
phpList supports the substituting of attributes into your messages recorded from your subscribers by using [ATTRIBUTE]
tags in the content of the message.
It doesn't, however, support this in message subjects. A personalized e-mail subject line goes a long way towards engaging your readers, so let's modify phpList to perform the same attribute substitution in the subject line.
Open admin/sendemaillib.php
and look for the following stanza, around line #757:
if (!TEST) { if ($hash != 'forwarded' || !sizeof($forwardedby)) { $fromname = $cached[$messageid]["fromname"]; $fromemail = $cached[$messageid]["fromemail"]; $subject = $cached[$messageid]["subject"]; } else { $fromname = ''; $fromemail = $forwardedby['email']; $subject = $GLOBALS['strFwd'].': '.$cached[$messageid]["subject"]; }
This is the logic that decides whether an e-mail is being sent to a subscriber or being forwarded to a third party by a subscriber. Instead of interfering with this code, we'll do our modifications directly afterwards.
Directly after this stanza, paste in the following code:
// START HACK - Perform attribute substitution in the subject if (is_array($user_att_values)) { foreach ($user_att_values as $att_name => $att_value) { $subject = str_ireplace("[$att_name]",$att_value, $subject); } } // END HACK - Perform attribute substitution in the subject
This cycles through the in-scope variable—$user_att_values
and performs case-insensitive attribute replacement against the $subject
variable.
Now we can attempt to send a message with a personalized subject line:
The messages are received and individually customized for our subscribers:
You'll notice in the original stanza before our pasted hack that it's also possible for a subscriber to click a link to forward a message that they received onto a third party. This will become a problem for our attribute-substitution code, as we don't have any attributes on record for the third party. The third party will receive a message without any attribute substitution:
18.222.21.175