[mod] Customizing confirmation emails with custom attributes

3rd party code for pl

Moderators: Dragonrider, J_S, Hernol, vancoovur, H2B2, Heritage

[mod] Customizing confirmation emails with custom attributes

Postby H2B2 » 2:06am, Fri 24 Mar, 2006

Hi,

I ran into some problems customizing my confirmation emails and could use some help.

I would like the confirmation emails to include the firstname of a user by using the placeholder [FIRSTNAME], like this:

Dear [FIRSTNAME],

Almost welcome to our newsletter(s) ...

Someone, hopefully you, has subscribed your email address to the following newsletters:

[LISTS]

etc.



For some reason the [FIRSTNAME] placeholder doesn't work and just displays [FIRSTNAME] instead of the user's name. That's strange because the [LISTS] placeholder does work...

My subscription form has 2 input fields:
email
firstname => which is attribute1

And 2 selection boxes for list subscriptions.

Any help would be appreciated!
Last edited by H2B2 on 7:28am, Fri 29 Feb, 2008, edited 1 time in total.
H2B2
phpList Guru
 
Posts: 5890
Joined: 1:51am, Wed 15 Mar, 2006

Postby Totto » 9:45pm, Fri 24 Mar, 2006

Look at this thread - it explains how to be able to add user attributes placeholders in your emails. Hope that helps!
To all forum users: Search the forums when you got a question first! Your question may have already been asked many times before and also many times answered. The search feature is your best friend on any forums of this kind!
Totto
PL Master
 
Posts: 370
Joined: 11:20pm, Tue 31 Jan, 2006

Postby H2B2 » 11:16pm, Sun 26 Mar, 2006

Thanks for pointing out this thread. I'll take a look and see how far i get in solving this problem.

Cheers!
H2B2
phpList Guru
 
Posts: 5890
Joined: 1:51am, Wed 15 Mar, 2006

Postby H2B2 » 9:32pm, Wed 24 May, 2006

Well, it appears most placeholders do not work in the confirmation mails. The placeholders [LISTS], [CONFIRMATIONURL], etc. are some of the exceptions.

A bug report has been filed (http://mantis.tincan.co.uk./view.php?id=3288) and hopefully this problem will be resolved in release 2.11.

Still, most -if not all- placeholders do work in list messages to subscribers.
H2B2
phpList Guru
 
Posts: 5890
Joined: 1:51am, Wed 15 Mar, 2006

Postby H2B2 » 12:44am, Tue 05 Dec, 2006

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]
H2B2
phpList Guru
 
Posts: 5890
Joined: 1:51am, Wed 15 Mar, 2006

Postby rjc » 12:46am, Tue 12 Dec, 2006

Hi Guys,

I have come up with a solution to the problem of Placeholders not being processed in System Emails (eg subscribe etc - See Issue 3288). I'm just new to phplist, but was disappointed that the first email a user receives after registering weren't able to be personalised... :( A bit of a letdown, as personalisation was the reason I went with phplist :?

This is what I did. First, I created two functions in the file admin/commonlib/lib/userlib.php. The first processes Custom Placeholders (user-defined), the second some System-defined Placeholders:

Before the ending ?>, add:

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):
*/

$systemmessage = ereg_replace('\[DOMAIN\]', getConfig("domain"), $systemmessage);
$systemmessage = ereg_replace('\[WEBSITE\]', getConfig("website"), $systemmessage);

return $systemmessage;
}


(As an aside, I have shortened the second procedure above to only those ones which successfully work. I show the full one below with all my comments and the placeholders which don't work. Someone eslse may have more success).

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 users are imported from csv
$subscribemessage = RJC_ReplaceCustomPlaceholders($subscribemessage,$userid);
$subscribemessage = RJC_ReplaceBuiltinPlaceholders($subscribemessage,$userid);
// END RJC ADDED



It seems to process Custom (userdefined) placeholders fine; since I don't know php or sql very well, I wasn't able to get any more of the Globals working (see Full Function below). Maybe someone with a bit more skill can do so...

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... Another day. :)


As mentioned above, I list the full Builtin Placeholders function below. I only have a few builtins working (limited by lack of php & sql knowledge).

--- FULL FUNCTION ---

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 :) */
$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;
}
rjc
PL Nut
 
Posts: 28
Joined: 10:57pm, Mon 11 Dec, 2006

Postby H2B2 » 4:38am, Tue 12 Dec, 2006

Hi rjc,

Finally someone brave enough to tackle this issue! Thanks for your contribution.

I whish I could help, but my PHP coding by far isn't what I would like it to be.
H2B2
phpList Guru
 
Posts: 5890
Joined: 1:51am, Wed 15 Mar, 2006

Postby rain999 » 8:52am, Wed 18 Apr, 2007

Hello,

Has anyone worked with RJC's fixes to help him troubleshoot them? Is there a new release of PHPlist on the horizon with the ability to use custom placeholders within system eMails and subject lines?

Thanks for your time,
-r999
rain999
phplister
 
Posts: 11
Joined: 5:42am, Tue 17 Apr, 2007


Return to Add-ons, Contributions, Mods, Plug-ins

Who is online

Users browsing this forum: No registered users and 0 guests