views:

812

answers:

3

I need to send out an email with multiple image attachments from PHP. I currently have a test set up that uses two hard coded images. I compile the email with al the necessary headers and send it out. However, when I receive it, it only shows the first image as an attachment. The second image seems to be ignored (tested with both Groupwise and Gmail).

When I view the source of my email the following is what I see after the by the server generated headers. Apparently both attachments (images) are in there but only the first one is showing up as an attachment.

Any help would be greatly appreciated.

This is a multi-part message in MIME format.

--==Multipart_Boundary_x38e1b83d34375e183a2fdcd6a9c001f8x
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

my message text

--==Multipart_Boundary_x38e1b83d34375e183a2fdcd6a9c001f8x
Content-Type: image/gif;
 name="image1.gif"
Content-Disposition: attachment;
 filename="image1.gif"
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAABEAAAAMCAIAAAALR8HoAAABgElEQVQoFZWQzSuEURTG7z3n3Pt+

*[-- snip --]*

SaHPETExQ6HQ0BB4Z8FwTr/KHVc/AJ98jIf2BGdKAAAAAElFTkSuQmCC

--==Multipart_Boundary_x38e1b83d34375e183a2fdcd6a9c001f8x--

--==Multipart_Boundary_x38e1b83d34375e183a2fdcd6a9c001f8x
Content-Type: image/gif;
 name="image2.gif"
Content-Disposition: attachment;
 filename="image2.gif"
Content-Transfer-Encoding: base64

iVBORw0KGgoAAAANSUhEUgAAAKMAAAAyCAIAAAC/NPwxAAAAA3NCSVQICAjb4U/gAAAACXBIWXMA

*[-- snip --]*

yh4+kv39P/vticlfC0Muodov+5posktKGGb7/2pscsAoKykp2W8fTH4Exv1tEEbD3NNGwbi/y8do
mNnbKPwf2Oju7uv54J4AAAAASUVORK5CYII=

--==Multipart_Boundary_x38e1b83d34375e183a2fdcd6a9c001f8x--
+1  A: 

Is whole mail declared as multipart/mixed as it should be?

$headers .= 'MIME-Version: 1.0'. "\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"". "\n";
vartec
I started out with this but it didn't seem to make any difference. Will try again in the morning.
Luke
+5  A: 

Going from memory:

SaHPETExQ6HQ0BB4Z8FwTr/KHVc/AJ98jIf2BGdKAAAAAElFTkSuQmCC

--==Multipart_Boundary_x38e1b83d34375e183a2fdcd6a9c001f8x--
^^^ DELETE THIS LINE ^^^

--==Multipart_Boundary_x38e1b83d34375e183a2fdcd6a9c001f8x

You shouldn't have two boundaries next to each other, and the "--" at the end is only for the end of the last part.

Greg
Thanks. I was under the impression that the line with -- was ending a specific block. Will test in the morning.
Luke
This is exactly what the problem was. Thanks!
Luke
+2  A: 

If it is okay for your purpose you could try to use PHPMailer (licensed under LGPL). It is very very easy to use and handles all the complicated mail stuff for you.

Hippo
Thanks! I will definitely look into that.
Luke