phplist

NOTE:: Before reporting an issue, make sure you are running the latest version, currently 3.3.1


View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003288phplist applicationSubscribe Processpublic20-05-05 20:3702-09-14 12:46
Reporteryan 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version2.8.12 
Target Version3.0.8Fixed in Version 
Summary0003288: placeholders in subscription messages
Description a placeholder like [DOMAIN] is not replaced by the actual domain. The actual domain seems to appear in the 'configure' page when you view it, but not in the messages actually sent out by the system, where you have [DOMAIN] as is, not the actual domain.
TagsNo tags attached.
Attached Files

- Relationships Relation Graph ] Dependency Graph ]
related to 0002705closed PHPList v2.11 release 
related to 0015504new Dynamic fields in Messag Subject 
child of 0003004closed problems with the 'notify' system message 'when users change their information' 

-  Notes
(0005890)
yan (reporter)
31-07-05 16:59

apart from [LISTS], [CONFIRMATIONURL], etc, no other placeholders can be used in the subscription messages. This is a shame. It would be nice to add attribute (i.e. admin-defined) placeholders to make the confirmation messages more user-friendly.

Example:
Welcome [FIRST NAME], please confirm the subscription of your email [EMAIL] to [LISTS] by clicking on this link: [CONFIRMATIONURL].
(0013880)
h2b2 (manager)
23-05-06 09:13

I can confirm Yan's report for version 2.10.02.
(0021685)
h2b2 (manager)
05-12-06 01:21

The problem of not being able to used custom placeholders -i.e., based on user attributes- in system messages, has been reported in several threads/posts, e.g.:
http://forums.phplist.com/viewtopic.php?p=12852#12852 [^]
http://forums.phplist.com/viewtopic.php?p=8944#8944 [^]
http://forums.phplist.com/viewtopic.php?p=12885#12885 [^]
http://forums.phplist.com/viewtopic.php?p=15796#15796 [^]

If this is a generalized issue -i.e., not specific to my particular system setup- than I think it would be advisable to add a note to the placeholder documentation page. Please let me know, and I will include it in the documentation.


I ran some tests to check which placeholders would work with specific system messages. These are my test results for Phplist 2.10.3 :

Message they receive when they subscribe
Message they receive when they confirm their subscription

Working
confirmationurl: [CONFIRMATIONURL]
preferencesurl: [PREFERENCESURL]
subscribeurl: [SUBSCRIBEURL]
unsubscribeurl: [UNSUBSCRIBEURL]
lists: [LISTS]
domain: [DOMAIN]
website: [WEBSITE]

Not working
1. all custom placeholders: e.g. [FIRSTNAME]
2. built-in placeholders:
Email: [EMAIL]
forward: [FORWARD]
forwardform: [FORWARDFORM]
forwardurl: [FORWARDURL]
listowner: [LISTOWNER]
preferences: [PREFERENCES]
signature: [SIGNATURE]
subscribe: [SUBSCRIBE]
userid: [USERID]
usertrack: [USERTRACK]
userdata: [USERDATA]
unsubscribe: [UNSUBSCRIBE]


Message that is sent when users change their information

Working
confirmationurl: [CONFIRMATIONURL]
preferencesurl: [PREFERENCESURL]
subscribeurl: [SUBSCRIBEURL]
unsubscribeurl: [UNSUBSCRIBEURL]
lists: [LISTS]
userdata: [USERDATA]

Not working
1. all custom placeholders: e.g. [FIRSTNAME]
2. built-in placeholders:
Email: [EMAIL]
forward: [FORWARD]
forwardform: [FORWARDFORM]
forwardurl: [FORWARDURL]
listowner: [LISTOWNER]
preferences: [PREFERENCES]
signature: [SIGNATURE]
subscribe: [SUBSCRIBE]
userid: [USERID]
usertrack: [USERTRACK]
unsubscribe: [UNSUBSCRIBE]
domain: [DOMAIN]
website: [WEBSITE]


Message users receive when they unsubscribe

Working
confirmationurl: [CONFIRMATIONURL]
preferencesurl: [PREFERENCESURL]
subscribeurl: [SUBSCRIBEURL]
unsubscribeurl: [UNSUBSCRIBEURL]
lists: [LISTS] (will state "All newsletters" instead of listing all lists)

Not working
1. all custom placeholders: e.g. [FIRSTNAME]
2. built-in placeholders:
Email: [EMAIL]
forward: [FORWARD]
forwardform: [FORWARDFORM]
forwardurl: [FORWARDURL]
listowner: [LISTOWNER]
preferences: [PREFERENCES]
signature: [SIGNATURE]
subscribe: [SUBSCRIBE]
userid: [USERID]
usertrack: [USERTRACK]
Userdata: [USERDATA]
unsubscribe: [UNSUBSCRIBE]
domain: [DOMAIN]
website: [WEBSITE]

Ref: http://forums.phplist.com/viewtopic.php?p=25357#25357 [^]
(0021693)
michiel (manager)
05-12-06 12:34

thanks, that's very useful
(0021913)
rjc (reporter)
12-12-06 01:05

I have verified the findings of h2b2 to be correct. I encountered the issue and was disappointed that the first email a user receives after subscribing was not able to be personalised (as in Dear [FIRSTNAME]), along with unsubscribe/update emails to their personal information.

The way I solved the issue was to add two of my own functions into the admin/commonlib/lib/userlib.php file. Then, from any page, a function call is made to my functions, which searches the supplied text and replaces all placeholders in it.

The first function processes Custom Placeholders (user-defined), the second some System-defined Placeholders. The Custom placeholders seem to process fine; the System-defined ones work for a couple, but not most (because I don't know enough php to get them going).

My php & sql knowledge is limited, so I really am guessing at the solution. It needs to be checked for security and breakability.

My two functions (put into admin/commonlib/lib/userlib.php):

function RJC_ReplaceCustomPlaceholders($systemmessage = '',$userid = 0) {
/* Function to replace Custom Placeholders with the proper values from the database (See Issue 3288) */
/* PS: Made so that placeholders are replaced in System Messages (eg Subscribe/Unsubscribe emails) */

/* Function works successfully. I guess it needs some sort of check to make sure parameters are supplied???
(to avoid a crash if $systemmessage or $userid are not supplied)
Someone should check for insecurities/inefficiencies as I don't know php well */

$rjc_user_att = getUserAttributeValues('',$userid);
while (list($att_name,$att_value) = each ($rjc_user_att)) {
if (eregi("\[".$att_name."\]",$systemmessage))
$systemmessage = eregi_replace("\[".$att_name."\]",$att_value,$systemmessage);
}
return $systemmessage;
}


function RJC_ReplaceBuiltinPlaceholders($systemmessage = '',$userid = 0) {
/* Function to replace Builtin Placeholders with the proper values from the database
PS: Made so that placeholders are replaced in System Messages (eg Subscribe/Unsubscribe emails)
(See Issue 3288):
NOTE: Does it cause a clash with specs as listed http://docs.phplist.com/Placeholders [^] (eg Allowed In)???
Maybe some of these should be removed from this function to avoid any problems??? */

/* The commented lines don't work successfully; someone who's more adept at select tables
should be able to help us out here...
I assume it needs to select tables from database for various user info; don't know php and sql enough
to do it confidently. */

/* I guess the function needs some sort of check to make sure parameters are supplied???
(to avoid a crash if $systemmessage or $userid are not supplied)
Someone should check for insecurities/inefficiencies as I don't know php well */

$systemmessage = ereg_replace('\[DOMAIN\]', getConfig("domain"), $systemmessage);
$systemmessage = ereg_replace('\[WEBSITE\]', getConfig("website"), $systemmessage);
/* The following work, but don't put a UID on the end of the url. The documentation http://docs.phplist.com/Placeholders [^]
seems to imply that a UID should be on the end... Job for someone Smile */
$systemmessage = ereg_replace('\[SUBSCRIBEURL\]', getConfig("subscribeurl"), $systemmessage);
$systemmessage = ereg_replace('\[CONFIRMATIONURL\]', getConfig("confirmationurl"), $systemmessage);
$systemmessage = ereg_replace('\[PREFERENCESURL\]', getConfig("preferencesurl"), $systemmessage);
$systemmessage = ereg_replace('\[UNSUBSCRIBEURL\]', getConfig("unsubscribeurl"), $systemmessage);
$systemmessage = ereg_replace('\[FORWARDURL\]', getConfig("forwardurl"), $systemmessage);

/* These following are meant to have url with uid, in the form of "this link" (ie <a>this link</a> */
// $systemmessage = ereg_replace('\[SUBSCRIBE\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[PREFERENCES\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[UNSUBSCRIBE\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[FORWARD\]', /*something goes here*/, $systemmessage);

// $systemmessage = ereg_replace('\[EMAIL\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[FORWARDFORM\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[LISTOWNER\]', /*something goes here*/, $systemmessage);
/* Signature result is blank, needs fixing (I think this is trying to give an html result)*/
// $systemmessage = ereg_replace('\[SIGNATURE\]', preg_replace('/src=".*power-phplist.png"/','src="powerphplist.png"',$PoweredByImage), $systemmessage);
// $systemmessage = ereg_replace('\[USERID\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[USERTRACK\]', /*something goes here*/, $systemmessage);

/* I guess for completeness I should put the lot, even [LISTS] is already processed (eg in index.php).
In theory, if they've already been processed in index.php, then the placeholders won't exist when this function is run, so
no harm done. This needs to be verified */
// $systemmessage = ereg_replace('\[USERDATA\]', /*something goes here*/, $systemmessage);
// $systemmessage = ereg_replace('\[LISTS\]', /*something goes here*/, $systemmessage);

return $systemmessage;
}



(The only two which really work are [DOMAIN] and [WEBSITE]. Someone with a bit more php & sql knowledge will have to get the other system placeholders going).


Then I modifed the following:

In index.php:

After:
$confirmationmessage = ereg_replace('\[LISTS\]', $lists, getUserConfig("confirmationmessage:$spage",$userdata["id"]));

Add:
// RJC ADDED - Includes User Placeholders in System Emails when a user Confirms their Subscription
$confirmationmessage = RJC_ReplaceCustomPlaceholders($confirmationmessage,$userdata["id"]);
$confirmationmessage = RJC_ReplaceBuiltinPlaceholders($confirmationmessage,$userdata["id"]);
// END RJC ADDED

After:
$unsubscribemessage = ereg_replace("\[LISTS\]", $lists,getUserConfig("unsubscribemessage",$userid));
Add:
// RJC ADDED - Includes User Placeholders in System Emails when a user Unsubscribes
$unsubscribemessage = RJC_ReplaceCustomPlaceholders($unsubscribemessage,$userid);
$unsubscribemessage = RJC_ReplaceBuiltinPlaceholders($unsubscribemessage,$userid);
// END RJC ADDED


In admin/subscribelib2.php:

After:
$subscribemessage = ereg_replace('\[LISTS\]', $lists, getUserConfig("subscribemessage:$id",$userid));

Add:
// RJC ADDED - Includes User Placeholders in System Emails when a user Subscribes
$subscribemessage = RJC_ReplaceCustomPlaceholders($subscribemessage,$userid);
$subscribemessage = RJC_ReplaceBuiltinPlaceholders($subscribemessage,$userid);
// END RJC ADDED


Before:
print '<title>'.$GLOBALS["strPreferencesTitle"].'</title>';

Add:
// RJC MODIFIED - Includes User Placeholders in System Emails when a user updates personal data
$message = RJC_ReplaceCustomPlaceholders($message,$userid);
$message = RJC_ReplaceBuiltinPlaceholders($message,$userid);
// END RJC MODIFIED


In admin/import1.php:

After:
$subscribemessage = ereg_replace('\[LISTS\]', $listoflists, getUserConfig("subscribemessage",$userid));

Add:
// RJC ADDED - Includes User Placeholders in System Emails when a user is added through Import
$subscribemessage = RJC_ReplaceCustomPlaceholders($subscribemessage,$userid);
$subscribemessage = RJC_ReplaceBuiltinPlaceholders($subscribemessage,$userid);
// END RJC ADDED


In admin/import3.php:

After:
$subscribemessage = ereg_replace('\[LISTS\]', $listoflists, getUserConfig("subscribemessage",$userid));

Add:
// RJC ADDED - Includes User Placeholders in System Emails when a user is added through Import
$subscribemessage = RJC_ReplaceCustomPlaceholders($subscribemessage,$userid);
$subscribemessage = RJC_ReplaceBuiltinPlaceholders($subscribemessage,$userid);
// END RJC ADDED



In admin/reconcileusers.php:

Before:
logEvent($GLOBALS['I18N']->get('Resending confirmation request to')." ".$userdata["email"]);

Add:
// RJC ADDED - Includes User Placeholders in System Emails when Reconcile users performed
$subscribemessage = RJC_ReplaceCustomPlaceholders($subscribemessage,$userid);
$subscribemessage = RJC_ReplaceBuiltinPlaceholders($subscribemessage,$userid);
// END RJC ADDED


In admin/commonlib/pages/importcsv.php:

After:
$subscribemessage = ereg_replace('\[LISTS\]', $listoflists, getUserConfig("subscribemessage",$userid));

Add:
// RJC ADDED - Includes User Placeholders in System Emails when a user Unsubscribes
$subscribemessage = RJC_ReplaceCustomPlaceholders($subscribemessage,$userid);
$subscribemessage = RJC_ReplaceBuiltinPlaceholders($subscribemessage,$userid);
// END RJC ADDED



As I mentioned, I don't know php, so someone really needs to go through it and check the code for insecurities/inefficiencies etc. For now my Custom Placeholders are showing up in (un)subscribe emails, along with system placeholders [DOMAIN] and [WEBSITE], so that's a start until someone else can get the rest of the System placeholders working (or at least those that are meant to according to documentation http://docs.phplist.com/Placeholders. [^]

I guess the concept could also be extended to not just the message body, but the subject line of (un)subscribe emails too...
(0054615)
duncanc (developer)
17-08-14 11:51

This enhancement is still being requested in the user forums, http://forums.phplist.com/viewtopic.php?f=35&t=41479 [^]

It looks straightforward to allow user attribute placeholders in the subscribe confirmation request, welcome, preferences, etc emails by reusing existing placeholder code from sendemaillib.php.

Are there any likely problems with this approach?
(0054621)
gingerling (administrator)
18-08-14 09:40

I like the sound of that enhancement. Would it be core or plugin, do you think duncanc?
(0054623)
duncanc (developer)
18-08-14 11:57

A change to core. There is already a function, getUserConfig in file admin/defaultconfig.php, that retrieves the email text and does some placeholder replacement.

Adding to that function looks to be the simplest approach.
(0054696)
duncanc (developer)
26-08-14 13:30

See GitHub pull request https://github.com/michield/phplist/pull/37 [^]


Copyright © 2000 - 2017 MantisBT Team
Powered by Mantis Bugtracker