Chapter 10. Hacking phpList

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:

  • Substituting user attributes in the message subject line
  • Sending system messages formatted as HTML instead of plain text
  • Creating a messages archive page
  • Sending messages through your e-mail client

Substituting user attributes in the subject line

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:

Substituting user attributes in the subject line

The messages are received and individually customized for our subscribers:

Substituting user attributes in the subject line

Caveat #1-no attribute substitution for a third party

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:

Caveat #1-no attribute substitution for a third party

Caveat #2-"Forward message" page displays an un-substituted subject

The mechanism for this forwarding process involves our subscriber clicking on a link in the message to forward the message. This page displays the subject of the message (un-substituted) when requesting the e-mail address to forward the message:

Caveat #2-"Forward message" page displays an un-substituted subject
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.21.175