[mod] Confirmation emails in HTML format

3rd party code for phpList

[mod] Confirmation emails in HTML format

Postby pavansut » 4:35am, Sat 28 Oct, 2006

Hi:
I am trying to add an image to the confirmation email which is recieved by the people who signup for the newsletter. The image code is fine...it brings up the image in the browser

However, in the confirmation email received in the inbox, it shows up only as html code not as an embeded image.

I wonder if any one has run into this problem.

Kind regards

Pav
pavansut
PL Nut
 
Posts: 25
Joined: 7:10pm, Sat 22 May, 2004
Location: NJ, USA

Postby H2B2 » 4:11pm, Sat 28 Oct, 2006

The confirmation email is a text message. And with the existing code does, it does not offer the same possibilities as html list messages. I think you will need to change the phplist code to send images with the confirmation email.
H2B2
Moderator
 
Posts: 7188
Joined: 1:51am, Wed 15 Mar, 2006

Images in confirmation emails

Postby pavansut » 6:45pm, Sat 28 Oct, 2006

that explains it! making a change to the code is beyond me, so I guess I'll have to do without images in the confirmation emails for now.

thx for your response.

pav
pavansut
PL Nut
 
Posts: 25
Joined: 7:10pm, Sat 22 May, 2004
Location: NJ, USA

I've used this code to allow html system messages

Postby EvilPuppetMaster » 4:44am, Wed 01 Nov, 2006

This is for 2.10.2, haven't tested in 2.10.3. No guarantees that it won't break anything, use at your own risk and test thoroughly!

You just need to make some modifications to the sendMailPhpMailer() function in the /admin/lib.php file. Once this is done, simply enter the raw html you want into the fields for 'Message users receive when they subscribe' etc. You can also enter HTML for any of the system emails that can be edited on the configuration page. The script will automatically send both html and text only versions of the email, for those email clients that don't support HTML. Note that the text-only version is made by simply stripping all the html tags so it won't look pretty unless you take care that the message still has line breaks in the right place when the html is stripped.

Anyway, on to the code!

In /admin/lib.php, find the sendMailPhpMailer() function, about line 246, and change it to the below. Lines that I've changed from the original have been commented with //customisation:

Code: Select all

function sendMailPhpMailer ($to,$subject,$message) {
  # global function to capture sending emails, to avoid trouble with
  # older (and newer!) php versions
  $fromemail = getConfig("message_from_address");
  $fromname = getConfig("message_from_name");
  $message_replyto_address = getConfig("message_replyto_address");
  if ($message_replyto_address)
    $reply_to = $message_replyto_address;
  else
    $reply_to = $from_address;
  $destinationemail = '';

  // customisation to allow HTML in system messages
  $html_message = $message;
  $message = preg_replace('/(<script.*\/script>)|(<style.*\/style>)/i', '', $message);
  $message = preg_replace('/<a\s*.*?href\s*=\s*("|\')([^"\']*?)("|\').*?>(.*?)<\/a>/i', "$4:\n$2\n", $message);
  $message = strip_tags($message);
  // end customisation

  if (!ereg("dev",VERSION)) {
    $mail = new PHPlistMailer('systemmessage',$to);
    $destinationemail = $to;
    $mail->add_html($html_message); // customisation
    $mail->add_text($message);
  } else {
    # send mails to one place when running a test version
    $message = "To: $to\n".$message;
    if ($GLOBALS["developer_email"]) {
      # fake occasional failure
      if (mt_rand(0,50) == 1) {
        return 0;
      } else {
        $mail = new PHPlistMailer('systemmessage',$GLOBALS["developer_email"]);
       $mail->add_html($html_message); // customisation
        $mail->add_text($message);
        $destinationemail = $GLOBALS["developer_email"];
      }
    } else {
      print "Error: Running CVS version, but developer_email not set";
    }
  }
  $mail->build_message(
      array(
        "html_charset" => getConfig("html_charset"),
        "html_encoding" => HTMLEMAIL_ENCODING,
        "text_charset" => getConfig("text_charset"),
        "text_encoding" => TEXTEMAIL_ENCODING)
      );
  return $mail->send("", $destinationemail, $fromname, $fromemail, $subject);
}

EvilPuppetMaster
phpList newbie
 
Posts: 2
Joined: 5:11am, Tue 09 May, 2006

Still no HTML system message

Postby anduigou » 4:01pm, Tue 14 Nov, 2006

I want the messages sent by PHPList to be sent by default in HTML. I am speaking about the messages received by the users when they are dealing with the system (subscription, preferences update, unsubscribe)

I have modified /admin/lib.php according to the previous post

But I still receive these messages as text. The tags that I introduced in the message are efficiently erased Smile, but this is not what I would like.

I'm using v2.10.2

Any idea ?
anduigou
phpLister
 
Posts: 11
Joined: 4:08pm, Mon 09 Oct, 2006
Location: Guadeloupe

Postby rjc » 11:57pm, Tue 12 Dec, 2006

I have tried the changes suggested by EvilPuppetMaster in 2.10.3 and it works fine! I have added css, html and images to my system (ie subscribe notification) emails, and they appear in all the glory of html :D

The only email which became corrupted was the email sent upon change of personal details. Occasionally, the ones that did work stopped working for a user (not sure why it just stopped after working properly).

I fixed these problems with a little fix as detailed below, so ALL the emails work ALL the time. (The problem was that after the database call to get the message, any " marks appeared as \" which messed up the html).


In the file admin/subscribelib2.php

After the code block:
[code]
$message = ereg_replace('\[LISTS\]', $lists, getUserConfig("updatemessage",$userid));
$message = ereg_replace('\[USERDATA\]', $datachange, $message);
if ($emailchanged) {
$newaddressmessage = ereg_replace('\[CONFIRMATIONINFO\]', getUserConfig("emailchanged_text",$userid), $message);
$oldaddressmessage = ereg_replace('\[CONFIRMATIONINFO\]', getUserConfig("emailchanged_text_oldaddress",$userid), $message);
} else {
$message = ereg_replace('\[CONFIRMATIONINFO\]', "", $message);
}
[/code]

Add this line of code:
[code]
$message = stripslashes($message); // Needed so html email will display properly; ie converts \" to "
[/code]


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

Add:
[code]
$subscribemessage = stripslashes($subscribemessage); // Needed so html email will display properly; ie converts \" to "
[/code]


In index.php

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

Add:
[code]
$confirmationmessage = stripslashes($confirmationmessage); // Needed so html email will display properly; ie converts \" to "
[/code]


After the code:
[code]
$unsubscribemessage = ereg_replace("\[LISTS\]", $lists,getUserConfig("unsubscribemessage",$userid));
[/code]

Add the code:
[code]
$unsubscribemessage = stripslashes($unsubscribemessage); // Needed so html email will display properly; ie converts \" to "
[/code]


The only problem is any images added are not embedded, so mail programs won't display the images until one clicks "Display Images". It would be nice if images could be embedded... but I'm not too fussed about embedded images right now. The emails look nice with just css and html.
rjc
PL Nut
 
Posts: 28
Joined: 10:57pm, Mon 11 Dec, 2006

Postby beagle17 » 8:48pm, Tue 16 Jan, 2007

EvilPuppetMaster, your hack is beautiful. But I am still seeking help (see below).

I don't understand why this software, without serious hacking, insists on sending text-only system messages. I want to use English and Chinese bilingually, and it works fine except for this incongruous problem.

Originally, I just made Chinese web pages and put links into the system messages I could adjust through the Configuration options on the PHPList interface.

But when my bilingual variables (yes, they work fine in English/Chinese) came out looking crazy (&#38936 etc.etc.) in the system email people get after changing their preferences profile, I started looking for a new solution.

EvilPuppetMaster's works for me, but the return characters don't come out well.

It looks like this:
Image

Good enough that I won't throw everything away, but not perfect. Any suggestions anyone?
beagle17
phpLister
 
Posts: 10
Joined: 10:40am, Sun 26 Nov, 2006
Location: Taipei

Postby Ennyaa » 10:55pm, Tue 06 Mar, 2007

THANK YOU SO MUCH!!! THIS HAS BEEN INVALUABLE TO ME! :D
Ennyaa
phpLister
 
Posts: 6
Joined: 10:32pm, Mon 05 Mar, 2007

Working with [VARIABLES]?

Postby dkellam » 7:20am, Mon 28 May, 2007

Hi,

This hack works fine with HTML, but does not seem to support the phplist [VARIABLES], such as [NAME]. How would one modify this to do that?

Thanks,

David
dkellam
phpList newbie
 
Posts: 4
Joined: 10:59am, Sun 15 Apr, 2007

Works Great. Avoid css style blocks

Postby RationalRabbit » 10:54am, Wed 10 Oct, 2007

Kudos EvilPuppetMaster and rjc!
Works great!!

My client did not want a confirm message, so I hacked so it would auto confirm, but was struggling with
1. Getting rid of the confirm message
2. Client wanting a formatted HTML welcome letter to be sent immediately on sign up.
This eliminated both problems.

:shock: Note: My HTML e-mail has a couple of graphics and several different colors - it is a nicely formatted page. As mentioned by rjc, if you have an e-mail account, such as gmail, you have to click to view the images - but then - you have to do that with most commercial e-mail that has images (as most do), so that doesn't bother me.

What IS a problem is my use of styles. I placed a style block then a head close at the top of my code. Although Outlook Express recovers fine from this evil deed, not so with gmail (and probably others) who strip the style codes out entirely.

I'm going to try reading a style sheet from my site. If that doesn't work, I'll have to inline them. Inline works fine.

LATER:
Not thinking - calling a stylesheet would be just the same. Just moved all to inline styles, and all is fine.
RationalRabbit
PL Nut
 
Posts: 15
Joined: 8:40am, Thu 23 Aug, 2007
Location: Seattle, Washington

Almost there ...

Postby dennislutz » 6:08pm, Thu 11 Oct, 2007

Good stuff! So now I've got an html message, but where do I put the <style> tag? or do you just add your style to each seperate element?
dennislutz
phpList newbie
 
Posts: 2
Joined: 5:31pm, Thu 04 Oct, 2007

Styles

Postby RationalRabbit » 2:04am, Tue 16 Oct, 2007

From my experience, it is best to convert your style declarations to inline. Otherwise, you are actually putting the style declarations outside of the HEAD tags. It will go out that way, but some e-mail clients will compensate while others will not. In the latter case, of course, you lose your formatting altogether.

It's probably possible to get around this by hacking the file and removing the end HEAD tag, then supplying your own in your HTML, but, as I understand it, some clients will strip out the style section anyway.
RationalRabbit
PL Nut
 
Posts: 15
Joined: 8:40am, Thu 23 Aug, 2007
Location: Seattle, Washington

Re: I've used this code to allow html system messages

Postby presentation trainer » 8:55am, Wed 17 Oct, 2007

Thanks for this EvilPuppetMaster:

You just need to make some modifications to the sendMailPhpMailer() function in the /admin/lib.php file. Once this is done, simply enter the raw html you want into the fields for 'Message users receive when they subscribe' etc. You can also enter HTML for any of the system emails that can be edited on the configuration page.


The user emails are working brilliantly, Now can anyone tell me where I can find the source code of the system emails I receive so that I can add HTML tags. They're a bit messy right now.
Thanks
presentation trainer
phpList newbie
 
Posts: 1
Joined: 8:17am, Wed 17 Oct, 2007

Re: I've used this code to allow html system messages

Postby DGibson111 » 7:24pm, Sun 11 Nov, 2007

EvilPuppetMaster wrote:This is for 2.10.2, haven't tested in 2.10.3. No guarantees that it won't break anything, use at your own risk and test thoroughly!

You just need to make some modifications to the sendMailPhpMailer() function in the /admin/lib.php file. Once this is done, simply enter the raw html you want into the fields for 'Message users receive when they subscribe' etc. You can also enter HTML for any of the system emails that can be edited on the configuration page. The script will automatically send both html and text only versions of the email, for those email clients that don't support HTML. Note that the text-only version is made by simply stripping all the html tags so it won't look pretty unless you take care that the message still has line breaks in the right place when the html is stripped.

Anyway, on to the code!

In /admin/lib.php, find the sendMailPhpMailer() function, about line 246, and change it to the below. Lines that I've changed from the original have been commented with //customisation:

Code: Select all

function sendMailPhpMailer ($to,$subject,$message) {
  # global function to capture sending emails, to avoid trouble with
  # older (and newer!) php versions
  $fromemail = getConfig("message_from_address");
  $fromname = getConfig("message_from_name");
  $message_replyto_address = getConfig("message_replyto_address");
  if ($message_replyto_address)
    $reply_to = $message_replyto_address;
  else
    $reply_to = $from_address;
  $destinationemail = '';

  // customisation to allow HTML in system messages
  $html_message = $message;
  $message = preg_replace('/(<script>)|(<style>)/i', '', $message);
  $message = preg_replace('/<a>(.*?)</a>/i', "$4:\n$2\n", $message);
  $message = strip_tags($message);
  // end customisation

  if (!ereg("dev",VERSION)) {
    $mail = new PHPlistMailer('systemmessage',$to);
    $destinationemail = $to;
    $mail->add_html($html_message); // customisation
    $mail->add_text($message);
  } else {
    # send mails to one place when running a test version
    $message = "To: $to\n".$message;
    if ($GLOBALS["developer_email"]) {
      # fake occasional failure
      if (mt_rand(0,50) == 1) {
        return 0;
      } else {
        $mail = new PHPlistMailer('systemmessage',$GLOBALS["developer_email"]);
       $mail->add_html($html_message); // customisation
        $mail->add_text($message);
        $destinationemail = $GLOBALS["developer_email"];
      }
    } else {
      print "Error: Running CVS version, but developer_email not set";
    }
  }
  $mail->build_message(
      array(
        "html_charset" => getConfig("html_charset"),
        "html_encoding" => HTMLEMAIL_ENCODING,
        "text_charset" => getConfig("text_charset"),
        "text_encoding" => TEXTEMAIL_ENCODING)
      );
  return $mail->send("", $destinationemail, $fromname, $fromemail, $subject);
}




Has anyone gotton this to work in 2.10.5? I tried and am not having any luck. Any tips are greatly appreciated!

--Danica
DGibson111
PL Nut
 
Posts: 31
Joined: 10:44pm, Wed 07 Nov, 2007

Postby BWWD2008 » 4:24am, Sun 10 Feb, 2008

Still not having any luck myself with the above

I try entering html code into the config page for the confirmation email and all that happens is the usual formatting gets removed as does the html so the emails now look even worse than they originally did

Im using version 2.10.5

Anyone got any fix, i just need to successfully ad some tables and a couple of images and links to all the system emails so that they match the same design and layout as the rest of the emails that get sent as the plain text looks really dull and loses the company feel that people have become used to

Thanks
BWWD2008
PL Nut
 
Posts: 33
Joined: 4:08am, Sat 09 Feb, 2008

Next

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

Who is online

Users browsing this forum: No registered users and 0 guests