phpMailer - netscape broken with inline images [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

phpMailer - netscape broken with inline images [SOLVED]

Post by Stryks »

Basically, I am trying to implement phpMailer for a registration system I am working on and I'm trying to send multipart emails with embedded images in the html part.

Outlook and Hotmail seem to be quite happy to show the page as intended, but Netscape mail seems to be a bit lost.

My embedding method is basically the following, though if the same mail loads perfectly with outlook, I'm not sure what I can change that will fix this without breaking the other.

Anyhow ...

Code: Select all

// Process HTML Email Body
	if (preg_match_all("/<img(.*?)>/si", $html_body, $matches)) {	
		for($i=0; $i<count($matches[0]); $i++) {

			// find and retain all important parameters for current link
			if(preg_match_all("/(height=['\"]|width=['\"]|class=['\"])(\S+?)['\"]/i", $matches[0][$i], $parameters)) {
				$parameters = " " . implode(" ", $parameters[0]);
			} else {
				$parameters = "";
			}

			// find and process the src - link each unique image once and set reference
			if(preg_match("/src=['\"](\S+?)['\"]/i", $matches[0][$i], $full_path)) {
				$prev_used = false;

				// Check each src against the previous ones to make sure the same image isn't linked twice
				for($x=0; $x<$i; $x++) {
					preg_match("/src=['\"](\S+?)['\"]/i", $matches[0][$x], $test_var);
					if ($full_path[1] == $test_var[1]) {
						$prev_used = true;
						break;
					}
				}
				// Link all unique entries.  Non unique ones are linked to the previously found link.
				if (!$prev_used) {
					$URL = explode("/", $full_path[1]);
					$mail->AddEmbeddedImage(PATH_LOCAL . "includes/email/e_images/" . $URL[count($URL)-1], "my-attach-" . $x, $URL[count($URL)-1]);
				}
			}
			// replace the original img with the new tags, including any other tags found
			$alt_name = explode("/", $full_path[1]);
			$alt_name = $alt_name[count($alt_name)-1];
			$html_body = str_replace($matches[0][$i], '<img alt="' . $alt_name . '" src="cid:my-attach-' . $x . '"' . $parameters . '>', $html_body);
		}
	}
I can post message source if that helps at all, but perhaps it is just something I'll have to live with.

Any help appreciated. Cheers

d11wtq | Please use

Code: Select all

tags - you should know this by now   [/color]
Last edited by Stryks on Mon Jul 18, 2005 9:14 pm, edited 1 time in total.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: phpMailer problem - netscape broken with inline images

Post by Roja »

Stryks wrote: I can post message source if that helps at all, but perhaps it is just something I'll have to live with.
It would help. The code you posted is only a processor, so without either the input or the output, it makes it hard to determine if its the transform that is a problem.

Output would be the most helpful, imho.
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post by Stryks »

The following is the message source from Netscape Mail - the same email collected via Outlook loads fine. Hotmail is fine but shows images as attachments, but I think thats normal.

Code: Select all

From - Mon Jul 18 21:51:26 2005
X-UIDL: 6eb4885b9d70b892f624d88094a5bf3f
X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000
Return-Path: <***********>
X-Original-To: ***********
Delivered-To: ***********
Received: from localhost (*********** &#1111;***********])
	by *********** (Postfix) with ESMTP id 59A424FCD9
	for <***********>; Mon, 18 Jul 2005 21:50:35 +1000 (EST)
Received: from *********** (&#1111;***********])
 by localhost (*********** &#1111;***********]) (amavisd-new, port 10024)
 with LMTP id 05292-01-71 for <***********>;
 Mon, 18 Jul 2005 21:20:35 +0930 (CST)
Received: from *********** (*********** &#1111;***********])
	by mail.***********.net (Postfix) with SMTP id 3B2A54FCD4
	for <***********>; Mon, 18 Jul 2005 21:50:33 +1000 (EST)
Received: (qmail 21787 invoked by uid 398); 18 Jul 2005 11:50:33 -0000
To: ***********
Subject: New Account Activation
X-PHP-Script: ***********/register.php for ***********, ***********
Date: Mon, 18 Jul 2005 11:50:33 +0000
From: *********** <***********>
Reply-To: *********** <***********>
Message-ID: <3af668d90c894150640b18b377dfb429@***********.com>
X-Priority: 3
X-Mailer: PHPMailer &#1111;version 1.73]
MIME-Version: 1.0
Content-Type: multipart/related;
	type=&quote;text/html&quote;;
	boundary=&quote;b1_3af668d90c894150640b18b377dfb429&quote;
X-Virus-Scanned: amavisd-new at ***********


--b1_3af668d90c894150640b18b377dfb429
Content-Type: multipart/alternative;
	boundary=&quote;b2_3af668d90c894150640b18b377dfb429&quote;

--b2_3af668d90c894150640b18b377dfb429
Content-Type: text/plain; charset = &quote;iso-8859-1&quote;
Content-Transfer-Encoding: 8bit


Registration Confirmed

Thank you for deciding you become a member.

In order to start using your new account, you must
activate your account so that we can be sure you
recieved this email properly.

 

To activate your account, copy the URL below into the address bar of your
browser.

%url%

 

If you did not request a membership with us or
have encountered any problems with the
registration or activation process, please reply
to this email with a description of the problem. 


--b2_3af668d90c894150640b18b377dfb429
Content-Type: text/html; charset = &quote;iso-8859-1&quote;
Content-Transfer-Encoding: 8bit


<html>
<style type=&quote;text/css&quote;>
<!--
.blueBox {
	border: 2px solid #0033CC;
}
A{
  color: #666666;
  text-decoration: none;
}
A:hover {
  color: #AABBDD;
  text-decoration: underline;
}
A.silent{
  color: #000000;
  text-decoration: none;
}

body,td,th {
	color: #000000;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.headText {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 16px;
	font-weight: bold;
	color: #666666;
}
-->
</style>
<body>
<table width=&quote;550&quote; border=&quote;0&quote; align=&quote;center&quote; cellpadding=&quote;0&quote; cellspacing=&quote;0&quote; class=&quote;blueBox&quote;>
	<tr>
		<td width=&quote;15&quote;>&nbsp;</td>
		<td width=&quote;332&quote;><img alt=&quote;image1.jpg&quote; src=&quote;cid:my-attach-0&quote; width=&quote;326&quote; height=&quote;121&quote;></td>
		<td width=&quote;183&quote; align=&quote;right&quote;><img alt=&quote;image2.jpg&quote; src=&quote;cid:my-attach-1&quote; width=&quote;76&quote; height=&quote;121&quote;></td>
		<td width=&quote;16&quote;>&nbsp;</td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td colspan=&quote;2&quote;><img alt=&quote;topbar.jpg&quote; src=&quote;cid:my-attach-2&quote; width=&quote;515&quote; height=&quote;22&quote;></td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td colspan=&quote;2&quote;>
			<p></p>
			<p class=&quote;headText&quote;>Registration Confirmed</p>
			<p>Thank you for deciding you become a member.</p>
			<p>In order to start using your new account, you must activate your account so that we can be sure you recieved this email properly.</p>
			<p>&nbsp;</p>
			<p>To activate your account, click <a href=&quote;%url%&quote;>HERE</a></p>
			<p> or copy the URL below into the address bar of your browser.</p>
			<p>%url%</p>
			<p>&nbsp;</p>
			<p>If you did not request a membership with us or have encountered any problems with the registration or activation process, please reply to this email with a description of the problem. </p>
			<p>&nbsp;</p>
		</td>
		<td>&nbsp;</td>
	</tr>

</table>
</body>
</html>



--b2_3af668d90c894150640b18b377dfb429--
--b1_3af668d90c894150640b18b377dfb429
Content-Type: application/octet-stream; name=&quote;image1.jpg&quote;
Content-Transfer-Encoding: base64
Content-ID: <my-attach-0>
Content-Disposition: inline; filename=&quote;image1.jpg&quote;

/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAPAAA/+4ADkFkb2JlAGTAAAAAAf/b
AIQABgQEBAUEBgUFBgkGBQYJCwgGBggLDAoKCwoKDBAMDAwMDAwQDA4PEA8ODBMTFBQTExwbGxsc
<clipped>
UAoBQCgFAKAUAoBQCgFAKAUAoBQCgFAKAUAoBQCgFAKAUAoBQCgFAKAUAoBQCgFAKAUAoBQCgFAK
AUAoBQCgFAKAUAoBQCgFAKAUAoBQCgFAKAUAoBQCgFAKAUAoBQH/2Q==


--b1_3af668d90c894150640b18b377dfb429
Content-Type: application/octet-stream; name=&quote;image2.jpg&quote;
Content-Transfer-Encoding: base64
Content-ID: <my-attach-1>
Content-Disposition: inline; filename=&quote;image2.jpg&quote;

/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAPAAA/+4ADkFkb2JlAGTAAAAAAf/b
AIQABgQEBAUEBgUFBgkGBQYJCwgGBggLDAoKCwoKDBAMDAwMDAwQDA4PEA8ODBMTFBQTExwbGxsc
<clipped>
bJs3ORiDikqJz+n1Wgr+c8YeXNkyOtzc5nsGEjW8g1OjTYcGQEkhRU7rZETqjxcFE5AgohWS/pQb
loFAoFAoFAoFAoFAoFAoFAoFAoFAoFAoFAoFAoP/2Q==


--b1_3af668d90c894150640b18b377dfb429
Content-Type: application/octet-stream; name=&quote;topbar.jpg&quote;
Content-Transfer-Encoding: base64
Content-ID: <my-attach-2>
Content-Disposition: inline; filename=&quote;topbar.jpg&quote;

/9j/4AAQSkZJRgABAgEASABIAAD/4QOQRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUA
AAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAUAAAAcgEyAAIAAAAUAAAAhodp
<clipped>
BwEAAAAAAAAAAAAAAAADBtKj01SkFVUWEQABAgUFAAAAAAAAAAAAAAAAAQIRURJSA6ITU6MU/9oA
DAMBAAIRAxEAPwBL8c27OYrUJPFit1PFoQ//0GYAP//RS9o5OFlpQkm7l4+xgsVkf//Z


--b1_3af668d90c894150640b18b377dfb429--
The clips and blanked areas are for size and privacy, I'm sure you understand. The images are all OK.

Also, the %url% is just a tag which is substituted out before sending. It is disabled for now until I can get this working. Well ... hopefully.

In Netscape Mail the image locations appear broken, but they are shown as attachments and they display properly if saved.

Hope this helps.
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post by Stryks »

No ideas anyone?

This is doing my head in.
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post by Stryks »

The problem is both extremely simple and damn hard to locate.

The problem is with the content type setting of AddEmbeddedImage.

By default it goes to octet/stream, which is fine for pretty much everything else, but netscape requires it to be either image/gif or image/jpg, depending on the image type.

I'm going to formulate all of this into a extender class of sorts, so I'll post it back in case someone finds it useful.
Post Reply