[mod] Embedding images in Content section

3rd party code for phpList

[mod] Embedding images in Content section

Postby rjc » 5:56am, Tue 29 May, 2007

Hello All,

Maybe someone can answer this question, and offer a solution!

After reading some forum posts, it's clear that phpList embeds any images/pictures in the Template, but any images added in the Content section are not embedded.

This causes trouble on the receiving end, as most email programs these days hide non-embedded images and spit out a message saying: "Some pictures have been blocked to prevent the sender from identifying your computer. Click here to download pictures". The problem is, most people don't bother clicking to see the pictures. If the pictures were embedded, this would not happen, they would just show up.

My question is, why doesn't phpList embed images in the Content section. Is there some reasoning/philosophy behind it?

My second question is, how can I make phpList embed all images, not just those in the Template, so that my mailing list can see images without having to do extra clicks (that most people probably will not do)?

Many thanks!
rjc
PL Nut
 
Posts: 28
Joined: 10:57pm, Mon 11 Dec, 2006

Postby rjc » 5:54pm, Fri 14 Sep, 2007

In case anyone is wondering, I worked out how to embed images in the content section into emails. :lol:


IN admin/class.phplistmailer.php

AFTER:
$this->find_html_images($templateid);

ADD:
// RJC ADDED
$this->find_html_images($html);
// END RJC ADDED
rjc
PL Nut
 
Posts: 28
Joined: 10:57pm, Mon 11 Dec, 2006

Postby rjc » 5:14pm, Fri 05 Oct, 2007

Oh No! I've found that my work-around doesn't actually work for many cases! :cry:

Please ignore my post immediately above...

My first method worked... as long as that file had been uploaded somewhere as a file included in a template. Silly me to test using photos from an old template! It did NOT work for any "fresh-out-of-the-box" photos. A few more changes were needed, after spending MANY :x hours trying to work out what's going on!

For completeness, I will list the whole thing again in this post. Ignore my previous post.


In admin/class.phplistmailer.php

Change 1:

AFTER:
Code: Select all
$this->find_html_images($templateid);


ADD:
Code: Select all
$this->find_html_images($html);   // Not actually sure if this is needed; I'll leave it in for now because it's almost 3:00am


Change 2:

REPLACE:
Code: Select all
for($i=0; $i<count($images[1]); $i++){
  if($this->image_exists($templateid,$images[1][$i])){
    $html_images[] = $images[1][$i];
    $this->Body = str_replace($images[1][$i], basename($images[1][$i]), $this->Body);
  }
}


WITH:

Code: Select all
for($i=0; $i<count($images[1]); $i++){
  $html_images[] = $images[1][$i];
  $this->Body = str_replace($images[1][$i], basename($images[1][$i]), $this->Body);
}


Change 3:

AFTER:
Code: Select all
$this->Body = str_replace(basename($html_images[$i]), "cid:$cid", $this->Body);


ADD:
Code: Select all
} else {
  $content=file_get_contents($html_images[$i],FALSE,NULL);
  $content = base64_encode($content);
  $content_type = $this->image_types[substr($html_images[$i], strrpos($html_images[$i], '.') + 1)];
  $cid = $this->add_html_image($content, basename($html_images[$i]), $content_type);
  $this->Body = str_replace(basename($html_images[$i]), "cid:$cid", $this->Body);


The php function file_get_contents can read non-file-system images (ie images off a website), so images don't actually have to be uploaded.

My apologies to all those who tried the first fix without success. This one seems to now work fine in my tests.

Onwards phplist! May you incorporate all the fixes and enhancements that are provided amidst hours of relentless and infuriating code-searching!
rjc
PL Nut
 
Posts: 28
Joined: 10:57pm, Mon 11 Dec, 2006

Emebded Images

Postby Woodentigger » 6:44pm, Thu 15 May, 2008

Hi

I have a difficult client who INSISTS that theimages in the content of an html email coems up and not have the click here to download piuctures that MS Outlook insists on putting in place.

I tried the Mod posted in the forum whic did not work. Does anyone else know of a work around that works wiht PHP List 2.10.4?

Any assistanc would be greatly appreciated
Woodentigger
phpList newbie
 
Posts: 1
Joined: 6:38pm, Thu 15 May, 2008

Fix for above post

Postby pramilo » 12:22pm, Wed 28 May, 2008

Hi

First off, thanks to rjc for the excelent post.

However that post applys to PHP 5!!
If you are using php 4 you need to do a fix for it to work.

The line is, on "Change 3", replace the line that says:
$content=file_get_contents($html_images[$i],FALSE,NULL);

with
$content=file_get_contents($html_images[$i],false);

---

this will fix the behaviour in the previous post where images are not embedded correctly and don't show up in the emails.
please remeber that with Gmail, although the images are atteched to the messge they are never displayed automatically. This is Gmail's fault, not PHPlist. An effective way to test if it's working correctly is opening the message from Outlook 2003. If the images are correctly embedded Outlook will display them immediatelly.
pramilo
phpList newbie
 
Posts: 1
Joined: 12:16pm, Wed 28 May, 2008

code modified - still not working

Postby 0be1 » 2:00pm, Mon 02 Jun, 2008

At first when I modified the code all I was getting were blank pages and I finally worked through that one. Once I was able to get in I had a previously queued message that was suspended and I try to send it as a test message to my gmail and hotmail accounts and the images still showed up blank.

Am I to assume that these code changes for this particular problem work only on new messages? And let me also clarify that the original problem was when copy and pasting html code with images in the content section of creating a new message, the images were not showing up embedded like when using a template. Is that correct?

tia...

0be1
0be1
phpList newbie
 
Posts: 3
Joined: 12:01pm, Thu 03 Apr, 2008

Still not working

Postby 0be1 » 5:24pm, Mon 02 Jun, 2008

I created a new message and tried sending it out and the images still did not show up, at least in Google.

0be1
0be1
phpList newbie
 
Posts: 3
Joined: 12:01pm, Thu 03 Apr, 2008

Postby 0be1 » 6:56pm, Mon 02 Jun, 2008

I figured out the problem. It was due to not having full paths to the image files. Once I change those in my test file and resent it came through with images.

0be1
0be1
phpList newbie
 
Posts: 3
Joined: 12:01pm, Thu 03 Apr, 2008

Postby jvarrone » 7:00pm, Mon 04 Aug, 2008

rjc wrote:Oh No! I've found that my work-around doesn't actually work for many cases! :cry:

Please ignore my post immediately above...

My first method worked... as long as that file had been uploaded somewhere as a file included in a template. Silly me to test using photos from an old template! It did NOT work for any "fresh-out-of-the-box" photos. A few more changes were needed, after spending MANY :x hours trying to work out what's going on!

For completeness, I will list the whole thing again in this post. Ignore my previous post.


In admin/class.phplistmailer.php

Change 1:

AFTER:
Code: Select all
$this->find_html_images($templateid);


ADD:
Code: Select all
$this->find_html_images($html);   // Not actually sure if this is needed; I'll leave it in for now because it's almost 3:00am


Change 2:

REPLACE:
Code: Select all
for($i=0; $i<count>image_exists($templateid,$images[1][$i])){
    $html_images[] = $images[1][$i];
    $this->Body = str_replace($images[1][$i], basename($images[1][$i]), $this->Body);
  }
}


WITH:

Code: Select all
for($i=0; $i<count>Body = str_replace($images[1][$i], basename($images[1][$i]), $this->Body);
}


Change 3:

AFTER:
Code: Select all
$this->Body = str_replace(basename($html_images[$i]), "cid:$cid", $this->Body);


ADD:
Code: Select all
} else {
  $content=file_get_contents($html_images[$i],FALSE,NULL);
  $content = base64_encode($content);
  $content_type = $this->image_types[substr($html_images[$i], strrpos($html_images[$i], '.') + 1)];
  $cid = $this->add_html_image($content, basename($html_images[$i]), $content_type);
  $this->Body = str_replace(basename($html_images[$i]), "cid:$cid", $this->Body);


The php function file_get_contents can read non-file-system images (ie images off a website), so images don't actually have to be uploaded.

My apologies to all those who tried the first fix without success. This one seems to now work fine in my tests.

Onwards phplist! May you incorporate all the fixes and enhancements that are provided amidst hours of relentless and infuriating code-searching!


Many thanks for your work on this. Works perfectly on 2.10.5 and PHP5
jvarrone
phpLister
 
Posts: 10
Joined: 2:32am, Sun 21 Aug, 2005

any luck with css images?

Postby baden03 » 2:44pm, Thu 14 Aug, 2008

I am using css styles as part of my template file. Works great except that some of the style definitions are using images as background elements.

If I use an absolute u r l some email clients will block the external images entirely (Outlook) while some will give the user a choice to view them or keep them hidden (Thunderbird).

After searching and swimming in the phplist docs & forums, it seems this issue hast not been addressed. Has anyone else been able to have phplist embed the
"background-image" images along with the other template images?

Seems ripe for a Mod!
baden03
phpList newbie
 
Posts: 1
Joined: 9:51am, Tue 20 May, 2008

Postby Guest » 9:11am, Tue 19 Aug, 2008

...I've got some trouble with this hack.

when I upload the modified file I'm only getting a blank page in the browser

I'm using Version 2.10.5

Anybody else with this problem ?

I've got no old messages, which are wating...

thanks
Guest
 

Postby Guest » 5:48pm, Wed 03 Sep, 2008

jurijp wrote:...I've got some trouble with this hack.

when I upload the modified file I'm only getting a blank page in the browser

I'm using Version 2.10.5

Anybody else with this problem ?

I've got no old messages, which are wating...

thanks



I am having the same problem here as this person is.
Is there a solution to this is there something I missed please let us know.

thanks
Guest
 

Postby Guest » 3:56pm, Thu 04 Sep, 2008

same problem here

The blank page only occurs after you do the

Code: Select all
$this->Body = str_replace(basename($html_images[$i]), "cid:$cid", $this->Body);


change

I do see that there is a #@@@ at the end of the $this->body line, Tried moving it after the new addtion but same blank screen.

anyone know of a fix?
Guest
 

Postby Guest » 5:02pm, Thu 04 Sep, 2008

I fixed it

I had to add another closing " } " after the paste on step 3 and it seems to work now.

'left that #@@@ where it was.
Guest
 

Postby Guest » 11:07pm, Thu 04 Sep, 2008

focusedphil wrote:I fixed it

I had to add another closing " } " after the paste on step 3 and it seems to work now.

'left that #@@@ where it was.


I have tried everything under the sun and nothing is working. It's obvious that this works but not for me. Here is what I put in there. I have tried null, binary #@@@ and what ever else I have spent to much trying to figure this out, so my hats off to ya that can make it work. Oh yeh I dont do this for a living as you can see.

<php> 'image/gif',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpe' => 'image/jpeg',
'bmp' => 'image/bmp',
'png' => 'image/png',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'swf' => 'application/x-shockwave-flash'
);

function PHPlistMailer($messageid,$email) {
# parent::PHPMailer();
parent::SetLanguage('en','phpmailer/language/');
$this->addCustomHeader("X-Mailer: phplist v".VERSION);
$this->addCustomHeader("X-MessageID: $messageid");
$this->addCustomHeader("X-ListMember: $email");
$this->addCustomHeader("Precedence: bulk");
$this->Host = PHPMAILERHOST;
$this->Helo = getConfig("website");
$this->CharSet = getConfig("html_charset");
if (isset($GLOBALS['phpmailer_smtpuser']) && $GLOBALS['phpmailer_smtpuser'] != '') {
$this->SMTPAuth = true;
$this->Username = $GLOBALS['phpmailer_smtpuser'];
$this->Password = $GLOBALS['phpmailer_smtppassword'];
# logEvent('Sending authenticated email via '.PHPMAILERHOST);
}
$ip = gethostbyname($this->Host);
if ($GLOBALS["message_envelope"]) {
$this->Sender = $GLOBALS["message_envelope"];
$this->addCustomHeader("Errors-To: ".$GLOBALS["message_envelope"]);
}
if (!$this->Host || $ip == $this->Host) {
$this->Mailer = "mail";
# logEvent('Sending via mail');
} else {
$this->Mailer = "smtp";
# logEvent('Sending via smtp');
}
}

function add_html($html,$text = '',$templateid = 0) {
$this->Body = $html;
$this->IsHTML(true);
if ($text) {
$this->add_text($text);
}
$this->find_html_images($templateid);
$this->find_html_images($html);
}


function add_text($text) {
if (!$this->Body) {
$this->IsHTML(false);
$this->Body = html_entity_decode($text ,ENT_QUOTES, 'UTF-8' ); #$text;
# $this->Body = $text;
} else {
$this->AltBody = html_entity_decode($text ,ENT_QUOTES, 'UTF-8' );#$text;
}
}

function append_text($text) {
if ($this->AltBody) {
$this->AltBody .= html_entity_decode($text ,ENT_QUOTES, 'UTF-8' );#$text;
} else {
$this->Body .= html_entity_decode($text ,ENT_QUOTES, 'UTF-8' );#$text;
}
}

function build_message() {
}

function send($to_name = "", $to_addr, $from_name, $from_addr, $subject = '', $headers = '',$envelope = '') {
$this->From = $from_addr;
$this->FromName = $from_name;
if (strstr(VERSION, "dev")) {
# make sure we are not sending out emails to real users
# when developing
$this->AddAddress($GLOBALS["developer_email"]);
} else {
$this->AddAddress($to_addr);
}
$this->Subject = $subject;
if(!parent::Send()) {
#echo "Message was not sent <p>";
logEvent("Mailer Error: " . $this->ErrorInfo);
return 0;
}#
return 1;
}

function add_attachment($contents,$filename,$mimetype) {
// Append to $attachment array
$cur = count($this->attachment);
$this->attachment[$cur][0] = chunk_split(base64_encode($contents), 76, $this->LE);
$this->attachment[$cur][1] = $filename;
$this->attachment[$cur][2] = $filename;
$this->attachment[$cur][3] = $this->encoding;
$this->attachment[$cur][4] = $mimetype;
$this->attachment[$cur][5] = false; // isStringAttachment
$this->attachment[$cur][6] = "attachment";
$this->attachment[$cur][7] = 0;
}

function find_html_images($templateid) {
#if (!$templateid) return;
// Build the list of image extensions
while(list($key,) = each($this->image_types))
$extensions[] = $key;

preg_match_all('/"([^"]+\.('.implode('|', $extensions).'))"/Ui', $this->Body, $images);

for($i=0; $i<count>Body = str_replace($images[1][$i], basename($images[1][$i]), $this->Body);
}


if(!empty($html_images)){
// If duplicate images are embedded, they may show up as attachments, so remove them.
$html_images = array_unique($html_images);
sort($html_images);
for($i=0; $i<count>get_template_image($templateid,$html_images[$i])){
$content_type = $this->image_types[substr($html_images[$i], strrpos($html_images[$i], '.') + 1)];
$cid = $this->add_html_image($image, basename($html_images[$i]), $content_type);
$this->Body = str_replace(basename($html_images[$i]), "cid:$cid", $this->Body);#@@@
}else{
$content=file_get_contents($html_images[$i],FALSE,BINARY);
$content = base64_encode($content);
$content_type = $this->image_types[substr($html_images[$i]), strrpos($html_images[$i], '.') + 1)];
$cid = $this->add_html_image($content, basename($html_images[$i]), $content_type);
$this->Body = str_replace(basename($html_images[$i]), "cid:$cid", $this->Body);
}
}
}
}

function add_html_image($contents, $name = '', $content_type='application/octet-stream') {
// Append to $attachment array
$cid = md5(uniqid(time()));
$cur = count($this->attachment);
$this->attachment[$cur][0] = $contents;
$this->attachment[$cur][1] = '';#$filename;
$this->attachment[$cur][2] = $name;
$this->attachment[$cur][3] = $this->encoding;
$this->attachment[$cur][4] = $content_type;
$this->attachment[$cur][5] = false; // isStringAttachment
$this->attachment[$cur][6] = "inline";
$this->attachment[$cur][7] = $cid;

return $cid;
}

function image_exists($templateid,$filename) {
$req = Sql_Query(sprintf('select * from %s where template = %d and (filename = "%s" or filename = "%s")',
$GLOBALS["tables"]["templateimage"],$templateid,$filename,basename($filename)));
return Sql_Affected_Rows();
}

function get_template_image($templateid,$filename){
$req = Sql_Fetch_Row_Query(sprintf('select data from %s where template = %d and (filename = "%s" or filename = "%s")',
$GLOBALS["tables"]["templateimage"],$templateid,$filename,basename($filename)));
return $req[0];
}

function EncodeFile ($path, $encoding = "base64") {
# as we already encoded the contents in $path, return $path
return chunk_split($path, 76, $this->LE);
}
}
Guest
 

Next

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

Who is online

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