[mod] Personalized subject line for list messages

3rd party code for phpList

Postby shumisha » 7:15pm, Fri 07 Apr, 2006

@tke852

well to make things more clear, if you only want to insert custom attributes in the body of the message, you do not need any mod of any kind. This is standard, whether using regular data such as 'email', or any other custom attribute you may want to create by yourself. Just add the name of the attribute between brackets, anywhere in a text or html message.
shumisha
PL Geek
 
Posts: 82
Joined: 8:06am, Tue 04 Apr, 2006

Thank You

Postby tke852 » 12:21pm, Fri 21 Apr, 2006

Thank You shumisha. I was wondering if that was the case. I will try it.

Thank You bigcashcreator. Your example might be something I will also try. It seems that future versions should have this built into the setup...That is, a way to add custom placeholders without having to go in and mess with the code.

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

Postby knonymouse » 9:51pm, Fri 05 May, 2006

I had a different reason to customize the subject line. I have a daily newsletter going out with repetition that pulls that day's file from a URL so each newsletter is different for each day.

With repetition, the subject line would be the same each day, and not distinctive in the list of emails.

So, I found how to make a change that sends out the newsletter with the day's date as part of the subject line. So instead of "The Newsletter", it will now say "Newletter for Friday 5 May" automatically.

The subject line in the message uses [NEWSDATE] as a placeholder for the variable date. Thus, the subject line as entered in the message is:
Newsletter for [NEWSDATE]


Changes made in sendemaillib.php at about line 668

Code: Select all
  if (!TEST) {
    if ($hash != 'forwarded' || !sizeof($forwardedby)) {
      $fromname = $cached[$messageid]["fromname"];
      $fromemail = $cached[$messageid]["fromemail"];
      $subject = $cached[$messageid]["subject"];
     
    # Add two lines to replace the placeholder in subject line
    $newsdate = date('l j F');
    $subject = eregi_replace("\[NEWSDATE\]",$newsdate,$subject);
    #


The date() function in PHP has a number of choices of symbols to indicate how the date will be displayed. 'l' gives the day of the week as a full word, 'j' gives the day in 1 or 2 numerals, and 'F' gives the month as a full word. Google for a manual on PHP that gives other choices.

The next line is really useful. It is used throughout several scripts wherever a placeholder is to be substituted. The third argument $subject is the string which contains the placeholder to be replaced. "\[NEWSDATE\]" is the placeholder, with '\' used to indicate the '[' is a literal and not part of code. $newsdate is the string that will be used to replace it. Simple.

The subject line in received emails has the substitution. The stored message under the queued tab or under the sent tab keeps the placeholder [NEWSDATE] as a literal.
knonymouse
PL Nut
 
Posts: 22
Joined: 12:54am, Thu 06 Apr, 2006

Re: Updated for phplist-2.10.1

Postby flug » 9:32pm, Mon 11 Sep, 2006

Putting together two ideas in this forum I came up with this--will replace any attribute in the subject line as long as it is of format [MYATTRIBUTE] (all uppercase, just as in message body for PHPlist). Also it will replace [NEWSDATE] with a date of form "Monday 4 September".

This would be a great little addition to PHPlist. Another nice feature would be to be able to add the date to the message body. Yet another--allow date format to be specified.

As it stands, you can change date format by fiddling with input to "time" function below; usual PHP time formatting elements apply.

2 changes needed to sendemaillib.php:

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

to
Code: Select all
    //changed to allow attribs in subject & inclusion of [NEWSDATE] for date in subject.
    if (!$mail->send("", $destinationemail, $fromname, $fromemail, plugAttributes($subject, $email))) {


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

add following function
Code: Select all


//added this function, adapted from the PHPlist user forum
//replace template vars in the subject line for customization based on user attributes
//should be used as upper case like [FIRST NAME] just as with attribs in body.
//also can include current date using [NEWSDATE]

function plugAttributes($str="", $email="")
{
    # Add two lines to replace the placeholder in subject line bhugh, 9/2006
    $newsdate = date('l j F');
    $str = eregi_replace("\[NEWSDATE\]",$newsdate,$str);
    #

   $custom_list=getUserAttributeValues($email);
   while (list($AttribName,$AttribValue) = each ($custom_list)) {
        foreach($custom_list AS $AttribName => $AttribValue) {
                $upAttribName=strtoupper($AttribName);
                $str = trim(str_replace("[{$upAttribName}]",$AttribValue,$str));
        }
   }
   return $str;
}


function addAttachments($msgid,&$mail,$type) {
flug
PL Nut
 
Posts: 25
Joined: 12:17am, Mon 28 Aug, 2006

Problem with attribute

Postby lizc » 4:14pm, Thu 19 Oct, 2006

Hi

In the body of my emails I have tried both [First Name] which is exactly as my attribute is configured and also [FIRST NAME] but neither work. I just get an email which says Dear [FIRST NAME] or [First Name].

Any ideas please?

Liz
lizc
phpLister
 
Posts: 7
Joined: 10:43am, Tue 26 Sep, 2006
Location: Spain

Postby bigcashcreator » 4:51pm, Thu 19 Oct, 2006

I had the same problem when I used spaces in my attributes....don't know why it does, but try to make an attribute w/o spaces...[firstname]. Also at the beginnig of this topic there is code you need to replace in your files...Let me know if you need help.
bigcashcreator
PL Nut
 
Posts: 25
Joined: 12:02am, Wed 29 Mar, 2006
Location: Boise, ID

Still having trouble

Postby lizc » 5:25pm, Thu 19 Oct, 2006

Hi again

Have replaced the code as shown above and have changed attribute to [firstname] and I'm still getting Hi [firstname] in my email.

This is the file I've changed admin/sendemaillib.php

My code now looks like this:

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"];
}

$theSubject = plugAttributes($subject, $email);
if (!$mail->send("", $destinationemail, $fromname, $fromemail, $theSubject)) {
logEvent("Error sending message $messageid to $email ($destinationemail)");
return 0;
} else {
return 1;
}
}
return 0;
}

//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;
}

function addAttachments($msgid,&$mail,$type) {


Have I lost the plot??

Thanks

Liz
lizc
phpLister
 
Posts: 7
Joined: 10:43am, Tue 26 Sep, 2006
Location: Spain

admin attributes in "from" field

Postby pamperedlist » 4:53am, Fri 03 Nov, 2006

It looks like there are some folks here who might be able to help me with this question:

I'm using the older functionality to utilize Admin Attributes such as [listowner.attribute], which works great.

I'd like to be able to put [listowner.email] into the "from" field of the message, so that if I send the same message to a number of different lists, the "from" email address is the owner of each list.

Any ideas? Thanks in advance!

Mike
pamperedlist
PL Nut
 
Posts: 18
Joined: 6:23pm, Fri 04 Aug, 2006

Postby kahethu » 1:05am, Thu 09 Nov, 2006

stephenrs wrote:
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.


I'm a new user and just installed this on version 2.10.3.

It seems to get "stuck" for ever as it processes the mail queue.

Any ideas?

Simon
kahethu
PL Nut
 
Posts: 15
Joined: 12:59am, Thu 09 Nov, 2006

Unable to get personalization using field

Postby smtotman » 1:42am, Tue 14 Nov, 2006

I have been unable to get this to work as outlined above. I am trying to have the thank you page that is returned when registering be personalized with the contact name in the form, but so far have not been able to get it to work. Any ideas as to what I should be putting in there? Have tried [Contact] as that is the name of the attribute I want to use.
smtotman
phpLister
 
Posts: 5
Joined: 4:55pm, Sun 12 Nov, 2006

Postby dimeco » 3:20am, Tue 10 Apr, 2007

We're also using 2.10.4

and the code obviously does not match up (i.e., to comment out line 53?)

Is it possible to be told *exactly* what lines of code appear just before and after the insertion of the new code?

For us, it also repeatedly "looped" but did not actually mail out. This is kinda urgent as a requirement for us.

:?
dimeco
phpList newbie
 
Posts: 4
Joined: 3:15am, Tue 10 Apr, 2007

Postby Hajo » 6:58pm, Thu 17 May, 2007

I would also like to put in my begging vote for a working script change to support subject line attributes in current (2.10.4) and future versions of PHPList.

I'm illiterate at PHP coding, but I imagine there are a lot of talented people out there capable of providing this much needed addition.

Anyone?

TIA,

Hajo
Hajo
phpList newbie
 
Posts: 4
Joined: 6:44pm, Thu 17 May, 2007

adding list title support

Postby blvrs2 » 12:26pm, Mon 28 May, 2007

This thread is awesome. And it directed me in what I needed.
I need a subject line that includes the name of the template. So I can use nucleus to process the e-mail into my weblog.

So I added two more template vars
[LISTNAME] to insert the listname
[TEMPLATENAME] to insert the template name.

I replaced from the original sendmaillib.php the following code

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

with
Code: Select all
    if (!$mail->send("", $destinationemail, $fromname, $fromemail,plugAttributes($subject,$email,$messageid))) {


and added to function plugAttributes at line 711 (before the AddAttachement function )
The code for the plugAttributes is
Code: Select all
//added this function, adapted from the PHPlist user forum
//replace template vars in the subject line for customization based on user attributes
//should be used as upper case like [FIRST NAME] just as with attribs in body.
//also can include current date using [NEWSDATE]
//also can include list name (title) using [LISTNAME]
//also can include template name using [TEMPLATENAME]
function plugAttributes($str="", $email="",$messageid=0)
{
    # Add two lines to replace the placeholder in subject line bhugh, 9/2006
    $newsdate = date('l j F');
    $str = eregi_replace("\[NEWSDATE\]",$newsdate,$str);
    #

   $custom_list=getUserAttributeValues($email);
   while (list($AttribName,$AttribValue) = each ($custom_list)) {
        foreach($custom_list AS $AttribName => $AttribValue) {
                $upAttribName=strtoupper($AttribName);
                $str = trim(str_replace("[{$upAttribName}]",$AttribValue,$str));
        }
   }
  $sql = "SELECT {$GLOBALS["tables"]["message"]}.template, {$GLOBALS["tables"]['template']} .title ";
  $sql .="FROM {$GLOBALS["tables"]['template']} LEFT JOIN {$GLOBALS["tables"]["message"]} ON ";
  $sql .= "{$GLOBALS["tables"]['template']} .id = {$GLOBALS["tables"]["message"]}.template ";
  $sql .= "WHERE {$GLOBALS["tables"]["message"]}.id=".$messageid;
  $templatename =Sql_Query($sql);
  $templatename = Sql_Fetch_array($templatename);
  if (!empty($templatename)){
     $templatename = $templatename['title'];
     
  } else {
     $templatename='';
  }
  $str = eregi_replace("\[TEMPLATENAME\]",$templatename,$str);   
   
  $sql = "SELECT {$GLOBALS["tables"]['list']} .name ";
  $sql .="FROM {$GLOBALS["tables"]['list']} LEFT JOIN {$GLOBALS["tables"]["listmessage"]} ON ";
  $sql .= "{$GLOBALS["tables"]['list']} .id = {$GLOBALS["tables"]["listmessage"]}.listid ";
  $sql .= "WHERE {$GLOBALS["tables"]["listmessage"]}.id=".$messageid;
  $listname =Sql_Query($sql);
  $listname = Sql_Fetch_array($listname);
  $listname = $listname['name'];
  $str = eregi_replace("\[LISTNAME\]",$listname,$str);
  return $str;
}


I use PHPlist v. 2.10.4

So When I need the template name in the subject line, I add in the subject the template var [TEMPLATENAME]

A subject line for my purpose would look like
[[TEMPLATENAME]] What happenend last week

It would result in
[my adventures] What happenend last week

I hope this is also useful for someone else.
blvrs2
phpList newbie
 
Posts: 1
Joined: 11:59am, Mon 28 May, 2007

Postby Hajo » 4:32pm, Mon 28 May, 2007

I just tried the above code and I'm still getting the endless process queue in PHPList when sending messages. No messages are sent.

What are the server versions of PHP, MySQL etc for people that are successfully using this?

Has anyone else been able to use this script successfully in PHPList 2.10.4?

No luck here (yet).

My versions are:
Operating system Linux
Kernel version 2.6.15-1.2054_FC5
Machine Type x86_64
Apache version 1.3.37 (Unix)
PERL version 5.8.1
PHP version 5.2.0
MySQL version 4.0.27-standard
cPanel Build 10.9.0-RELEASE 10737

Hajo
Hajo
phpList newbie
 
Posts: 4
Joined: 6:44pm, Thu 17 May, 2007

comany name in subject

Postby matteoraggi » 10:03pm, Tue 24 Jun, 2008

I need to put company name dinamically into subject line, some know if this is going for 2.10.5 ?
matteoraggi
PL Geek
 
Posts: 50
Joined: 5:22pm, Sun 11 Mar, 2007
Location: Italy

PreviousNext

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

Who is online

Users browsing this forum: Google [Bot] and 0 guests