[mod] PHP Code in Subject & Email message body

3rd party code for phpList

[mod] PHP Code in Subject & Email message body

Postby Mike_R » 6:41pm, Tue 24 Jul, 2007

WARNING : Thinking through this, I think it might present a potential security problem (if you have more than 1 admin that is).

Anyway, if you wish to modify your system, this will allow you to input tags into message subject and \ or body that look like this
Code: Select all
[PHP:return "Hello World";]
[PHP:\$me = 52; return Date("l", \$me);]


and PHP List will replace them with the value that is returned by your PHP snippet. NB you must use return and not echo. Also, remember all expressions must end with a semi-colon. If you get anything wrong in your PHP, you should see a message in the event log to let you know which statement was bad.

In /lists/admin/sendemaillib.php, search for
Code: Select all
  # remove any existing placeholders


and just before that line, add this

Code: Select all
$htmlmessage = parsePHPTags($htmlmessage);
$textmessage = parsePHPTags($textmessage);


Before the line
Code: Select all
    if (!$mail->send("", $destinationemail, $fromname, $fromemail, $custom_subject)) {

add the line

Code: Select all
$custom_subject = parsePHPTags($subject);


and before the function
Code: Select all
addAttachments($msgid,&$mail,$type) {


add this function in its entirety
Code: Select all
function parsePHPTags($instring) {
   $instring = htmlspecialchars_decode($instring, ENT_QUOTES);
   $startpos = 0;
   // find all locations of [PHP: in whatever has just been passed to us, then take out the string to be executed
   while ($startpos = strpos($instring, "[PHP:", $startpos)) {
      $endpos = strpos($instring, "]", $startpos);
      $commands[] = substr($instring, $startpos+5, $endpos-$startpos-5);
      $startpos++;
      }
   $outstring = $instring;
   foreach ($commands as $command) {
      $replacement = eval($command);
      if ($replacement) {
         $outstring = str_replace("[PHP:".$command."]",$replacement,$outstring);
      } else {
         logEvent('Executing command '.$command.' failed in function parsePHPTags');
      }
   }
   return $outstring;
}
Last edited by Mike_R on 7:22pm, Tue 14 Aug, 2007, edited 2 times in total.
Mike_R
PL Geek
 
Posts: 88
Joined: 10:34am, Wed 30 May, 2007

Postby Mike_R » 6:45pm, Tue 24 Jul, 2007

Can't seem to attach the .zip file containing my modified code. Should anyone want it, send me a pm and I'll email it over.
Mike_R
PL Geek
 
Posts: 88
Joined: 10:34am, Wed 30 May, 2007

Postby LordMerlin » 1:48pm, Wed 25 Jul, 2007

What is in the Zip file?
LordMerlin
PL Nut
 
Posts: 35
Joined: 10:50am, Mon 15 May, 2006
Location: Johannesburg, South Africa

Postby Mike_R » 9:41pm, Wed 25 Jul, 2007

When I modified the code, I made an rtf file with all the changes highlighted in bold + red (to make them easier to spot \ implement). Just thought if anyone was struggling to paste things in in the correct place this might help.
Mike_R
PL Geek
 
Posts: 88
Joined: 10:34am, Wed 30 May, 2007

Postby kuber » 7:05pm, Tue 31 Jul, 2007

I couldn't get it to work. Should I add the code in source view? Anyway I do it, the code's quotes are converted to " and the email I receive represents the same code I used.

this is what I used:

Code: Select all
[PHP:\$tomorrow = mktime(0,0,0,date(\"m\"),date(\"d\")+1,date(\"Y\")); return date(\"l, F j, Y\", \$tomorrow);]


I tried redoing the modification and I still am not able to render the code.

can you email me the .zip? I'd really appreciate if I could make this work out.

Thanks alot
kuber
phpLister
 
Posts: 14
Joined: 5:32pm, Fri 11 May, 2007

Postby Mike_R » 4:26pm, Wed 01 Aug, 2007

Drat, I didn't reason with the html conversion ... I think I might have to alter my changes slightly. Will have a look at this as soon as I get time.
Mike_R
PL Geek
 
Posts: 88
Joined: 10:34am, Wed 30 May, 2007

Postby kuber » 5:12pm, Wed 01 Aug, 2007

thanks
kuber
phpLister
 
Posts: 14
Joined: 5:32pm, Fri 11 May, 2007

Postby kuber » 4:31pm, Tue 14 Aug, 2007

Is there anyway I can help? If you give me some gu9ideline maybe I can help. I really need this tool.

Thanks
kuber
phpLister
 
Posts: 14
Joined: 5:32pm, Fri 11 May, 2007

Postby Mike_R » 7:19pm, Tue 14 Aug, 2007

Sorry, had forgotten that I said I was going to take another look at this. Have now edited my original post to take account of what I forgot. The line that's changed is the one at the top of
Code: Select all
function parsePHPTags($instring)


Have also done further testing and discovered that escaping the $ and " was unnecessary, so I've removed that bit of advice.

Or - If you pm me an email address I'll send you the rtf with highlighted changes if you like.
Mike_R
PL Geek
 
Posts: 88
Joined: 10:34am, Wed 30 May, 2007

Info In the Subject line

Postby Heritage » 2:58pm, Thu 17 Jan, 2008

Is there a way to get the code sent to me? I was trying to use it, but it seems if you do not get it exactly right the send feature hangs.

or is there a link to the file anywhere?

Did someone submit this as an official request in the new revision of the code?

Thanks.
Heritage
Moderator
 
Posts: 223
Joined: 3:25pm, Fri 23 Jun, 2006
Location: 800 720-7301

Postby devzie » 2:57am, Wed 30 Jul, 2008

from the above instructions i believe this:
Code: Select all
$custom_subject = parsePHPTags($subject);


should read:
Code: Select all
$subject = parsePHPTags($subject);


in order to be used in the function that follows where that line gets inserted.
devzie
phpList newbie
 
Posts: 4
Joined: 4:36am, Wed 08 Aug, 2007

Postby Heritage » 11:58am, Wed 30 Jul, 2008

Thanks. I will have to play with this later in a staging environment. Right now I am swamped with work.
Heritage
Moderator
 
Posts: 223
Joined: 3:25pm, Fri 23 Jun, 2006
Location: 800 720-7301

Postby devzie » 12:31pm, Wed 30 Jul, 2008

just to let people know, my html messages didnt get the PHPTags 'actioned' either.

something to play with when i get time, or if others wish to contribute. php tags are necessary for the coder in all of us :)
devzie
phpList newbie
 
Posts: 4
Joined: 4:36am, Wed 08 Aug, 2007

Re: [mod] PHP Code in Subject & Email message body

Postby locomot1f » 9:37pm, Thu 11 Mar, 2010

Would like to know if anybody is still working on this feature. It would be nice to be able to add PHP code. :D

The code provided did not execute the PHP code. it just spat out the text exactly.
locomot1f
phpLister
 
Posts: 7
Joined: 9:32pm, Thu 11 Mar, 2010

Re: [mod] PHP Code in Subject & Email message body

Postby locomot1f » 10:58pm, Thu 11 Mar, 2010

Okay, I got it working.
Could you give me some help on using includes? The code does some weird stuff.
It will spit it out on the admin page, but doesn't return the code on the e-mail. Still messing around with it. But so far, gotta say Big-Ups on supplying us with this feature.

Would be nice to see this added to the program in the future.

for people having trouble. I didn't have the
Code: Select all
 
<html>
    <body>
             ....
    </body>
</html>

in my message box.
locomot1f
phpLister
 
Posts: 7
Joined: 9:32pm, Thu 11 Mar, 2010

Next

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

Who is online

Users browsing this forum: No registered users and 2 guests