[mod] Personalized subject line for list messages

3rd party code for phpList

[mod] Personalized subject line for list messages

Postby Killjoy » 6:21pm, Sun 23 Jan, 2005

I am running 2.8.1.2.

I have been trying to modify PHPList so that you can personalize the subject line as well as the body of the message.

Here is what I have tried so far, but with very little luck.

file: sendemaillib.php

Line 53:
Commented out the line

line 449:
Added a call to custom function and cast it to a variable
Code: Select all
$theSubject=makeAttrib(stripslashes($message['subject']), $email);

line 451:
Change the last variable in the argument list from $cashed[$messageid]['subject'] to $theSubject
Code: Select all
if (!TEST) {
   if (!$mail->send("", $email, $cached[$messageid]["fromname"], $cached[$messageid]["fromemail"],$theSubject)) {
      logEvent("Error sending message $messageid to $email");
   }
}


line 457;
created a function called makeAttrib. This calls the function getUserAttributeValues.
getUserAttributeValues grabs the list of custom values (ie: firstname, last name, etc.)
Then makeAttribe returns the subject with the replaced values. or, at least, it is supposed to., but it doesnt. Bah!

Code: Select all
function makeAttrib($theSubject="", $email="")
{
   $custom_list=getUserAttributeValues($email);
   while (list($AttribName,$AttribValue) = each ($custom_list)) {
   //foreach($custom_list AS $AttribName => $AttribValue) {
   $theSubject = trim(eregi_replace("\[".$AttribName."\]",$AttribValue,$theSubject));
   }
   return $theSubject;
}


has anyone else had luck with this? I know that there have been talks on this forum about personalizing the confirmation emails and whatnot, but I am looking for a way to personalize every email.
Killjoy
phpList newbie
 
Posts: 1
Joined: 5:58pm, Sun 23 Jan, 2005

Postby stephenrs » 12:20am, Wed 15 Jun, 2005

Hi, I'm not sure if you ever got this to work, but using your code as a starting point, I got it to work just fine (version 2.8.12)

the big difference between what i decided to do, and your code is that i used a str_ireplace instead of eregi_replace (no need for a regular expression here, and str_ireplace is faster), and i set the value of $theSubject just before the call to mail->send(). use str_replace instead of str_ireplace for PHP versions prior to 5.

so, beginning around line 451, my code looks like:
Code: Select all
  if (!TEST) {
        $theSubject = plugAttributes($cached[$messageid]["subject"], $email);
        if (!$mail->send("", $email, $cached[$messageid]["fromname"], $cached[$messageid]["fromemail"],$theSubject)) {
                        logEvent("Error sending message $messageid to $email");
        }
  }
}

//srs added this function, clipped from the PHPlist user forum
//replace template vars in the subject line for customization based on user attributes
function plugAttributes($str="", $email="")
{
   $custom_list=getUserAttributeValues($email);
   while (list($AttribName,$AttribValue) = each ($custom_list)) {
        foreach($custom_list AS $AttribName => $AttribValue)
                $str = trim(str_replace("[{$AttribName}]",$AttribValue,$str));
   }
   return $str;
}



no other changes were needed, and the plugAttributes() function can also be used to customize the body of the message...

i didn't test your version, but either you were setting $theSubject too early, or your ereg_replace() wasn't working the way you expected (also, your foreach line was commented out).

thanks for the perfect starting point.
stephenrs
PL Nut
 
Posts: 23
Joined: 7:32pm, Fri 24 Sep, 2004

does work?

Postby silverbytes » 5:25pm, Thu 14 Jul, 2005

Hello stephenrs. Do I understand ok if I think adding the code you posted is the way to send personalized subjetcs?
Is hard for non developers to "install" plugins for phplist really so if you tell us how to add that functionallity would be great!

Thank you!
silverbytes
PL Nut
 
Posts: 45
Joined: 4:13pm, Fri 18 Mar, 2005

Postby stephenrs » 6:57pm, Thu 14 Jul, 2005

yes, that is correct. once you add this code, the subject line may be personalized based on attributes stored for users. for example, a subject line entered as:

Hello [Firstname]

would replace [Firstname] with the value of the attribute "Firstname" stored for each user.

best,

stephen
stephenrs
PL Nut
 
Posts: 23
Joined: 7:32pm, Fri 24 Sep, 2004

Postby akaara » 8:30pm, Mon 19 Sep, 2005

Has anyone else been able to get this to work (aside from stephenrs, who created it)???

I have changed my code to match the code given above, but I still get [FIRST NAME] in the subject line, instead of the list member's first name.

I can get their name to show up in the body of the message, so I know the person has a first name listed in the database.

Any ideas? Do I have to do anything else aside from changing the code mentioned above? (I am using version 2.8.12, by the way.)

-Veronica
akaara
phpList newbie
 
Posts: 3
Joined: 8:23pm, Mon 19 Sep, 2005

Postby stephenrs » 8:40pm, Mon 19 Sep, 2005

veronica,

you shouldn't have to do anything else, BUT the string that you enter between the brackets in your subject line must exactly match (including case sensitivity, depending on the version of PHP you're using) the name of the attribute you wish to replace.

so, if you use [Firstname] in the subject line, your attribute must be called exactly "Firstname".

...i would also avoid using spaces in attribute names, i'm not sure what effect this might have...

good luck.
stephenrs
PL Nut
 
Posts: 23
Joined: 7:32pm, Fri 24 Sep, 2004

Updated for phplist-2.10.1

Postby s01ipsist » 5:57am, Tue 20 Sep, 2005

Just for the interest of those who are now using phplist-2.10.1

The following 2 changes to sendemaillib.php will make the phplist evaluate variables in the Subject line.

1
change line
Code: Select all
if (!$mail->send("", $destinationemail, $fromname, $fromemail, $subject)) {

to
Code: Select all
$theSubject = plugAttributes($subject, $email);
if (!$mail->send("", $destinationemail, $fromname, $fromemail, $theSubject)) {


2
above the line
Code: Select all
function addAttachments($msgid,&$mail,$type) {

add following function
Code: Select all
//srs added this function, clipped from the PHPlist user forum
//replace template vars in the subject line for customization based on user attributes
function plugAttributes($str="", $email="")
{
   $custom_list=getUserAttributeValues($email);
   while (list($AttribName,$AttribValue) = each ($custom_list)) {
        foreach($custom_list AS $AttribName => $AttribValue)
                $str = trim(str_replace("[{$AttribName}]",$AttribValue,$str));
   }
   return $str;
}
s01ipsist
phpList newbie
 
Posts: 2
Joined: 5:46am, Tue 20 Sep, 2005

Postby akaara » 5:11pm, Tue 20 Sep, 2005

Thanks for the tip, stephenrs.

It was the case-sensitivity that was the problem. In the body of the message, PHPlist has you use all caps, no matter what the original case.

A little confusing at first, but it's all better now. :wink:

Thanks for the great mod!

-Veronica
akaara
phpList newbie
 
Posts: 3
Joined: 8:23pm, Mon 19 Sep, 2005

Postby bigcashcreator » 9:24pm, Thu 30 Mar, 2006

Thank you VERY VERY much for this! I started using it a few months ago, and it standard for every install I do!!!!
:D
bigcashcreator
PL Nut
 
Posts: 25
Joined: 12:02am, Wed 29 Mar, 2006
Location: Boise, ID

Postby shumisha » 8:10am, Tue 04 Apr, 2006

Hello all,

I had passed over phplist as the ability to personalize subject field was the one I missed. I did not checked the forum at first though !!

Great modification. However, it is stated that the changes are for 2.10.1. But now 2.10.2 is available, and is a recommanded upgrade for security reasons.
Could someone tell me if the thay have tried this hack on the new version, or if any changes are required ?

Thanks for your help !

Regards
shumisha
PL Geek
 
Posts: 82
Joined: 8:06am, Tue 04 Apr, 2006

Postby bigcashcreator » 1:07pm, Tue 04 Apr, 2006

Yes this mod works great with current version. I actually have 2.10.2 in a folder that I have added this mod too, which I copy to a new folder during a new installation. Works everytime! :lol:
bigcashcreator
PL Nut
 
Posts: 25
Joined: 12:02am, Wed 29 Mar, 2006
Location: Boise, ID

Postby shumisha » 2:33pm, Tue 04 Apr, 2006

thanks alan,

I am currently struggling to get started wiht phplist, so I'll see about this a bit later...
shumisha
PL Geek
 
Posts: 82
Joined: 8:06am, Tue 04 Apr, 2006

Postby tke852 » 2:32pm, Fri 07 Apr, 2006

How about attributes in the body of the text though? ...


Does anyone know the answer to this?

I was also wondering if anyone has applied this to other custom attributes?

I would like to further personalize html email by inserting some custom attributes within the body of a message.

Thanks
tke852
phpList newbie
 
Posts: 2
Joined: 2:23pm, Fri 07 Apr, 2006

Postby shumisha » 2:40pm, Fri 07 Apr, 2006

Hello,

just a bit of feedback. This hack works perfectly for me (2.10.2) and I am now a very happy phplist user (well I have not started yet sending out 2 or 3K emails , so I guess that's why I am still happy ?)

As for this

How about attributes in the body of the text though? ...


Does anyone know the answer to this?

I was also wondering if anyone has applied this to other custom attributes?

I would like to further personalize html email by inserting some custom attributes within the body of a message.

Thanks


well you can use the hack with any attributes, custom or standard. And to insert attribute in the body of the text, I am not sure I understand. This is what attributes are for. You do not need anything special. Just include the name of the attribute enclosed in brackets (ie [MY_ATTRIBUTE] ), and phplist will replace that by the corresponding value for each user, assuming you have created the attributes, and entered some data for each user.
shumisha
PL Geek
 
Posts: 82
Joined: 8:06am, Tue 04 Apr, 2006

Postby bigcashcreator » 6:32pm, Fri 07 Apr, 2006

Yes this mod takes care of the placeholders in the body of the emails as well. Just make the two changes to the sendlib.php file as shown above. I even "font up" the placeholders now and can do wild stuff. For instance, I can throw a giant birthday cake into a table and line up a cell over the top of the cake to pull the placeholder (attribute) that I created for date of birth [dob]. If I am pushing an opportunity I can use this one with the subject line:

[firstname] [lastname] from [city], how many more years will you allow to pass by...

Then in the body the picture of the cake with [dob] on the top that has been fonted up to look like icing!!! I cannot tell you how well this works!!! POWER TO PHPLIST! 8)
bigcashcreator
PL Nut
 
Posts: 25
Joined: 12:02am, Wed 29 Mar, 2006
Location: Boise, ID

Next

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

Who is online

Users browsing this forum: No registered users and 3 guests