Page 1 of 1

MIME types

Posted: Wed Apr 13, 2005 3:59 pm
by spacebiscuit
Hi,

I am trying to attach a jpg image to an email to be sent via php.

My email sends perfectly as does the jpg, only when I open the email once received the jpeg has .dat appended to it.

For example, mypicture.jpg becomes mypicture.jpg.dat

I think it has something to do with the MIME type, here is the code i am using:

Code: Select all

$filename="1.jpg";
	$attach_file=fopen($filename,"r");
	$contents=fread($attach_file,filesize($filename));
	fclose($attach_file);

	$part2["type"]=TYPEAPPLICATION;
	$part2["encoding"]=ENCBINARY;
	$part2["subtype"]="octet-stream";
	$part2["description"]=basename($filename);
	$part2["contents.data"]=$contents;
Any suggestions would be appreciated. Thanks!

Rob.

Posted: Wed Apr 13, 2005 5:09 pm
by Chris Corbyn
You need image/jpeg

obiously subtype here should be set to "jpeg" and i'd guess type will be TYPEIMAGE

Posted: Wed Apr 13, 2005 5:50 pm
by spacebiscuit
Thanks for the reply.

That does work the attachment arrives as a jpeg now but when I try and launch the attachment it crashes the application used to open it. Other similar attachments open fine!

Any ideas?

Thanks.

Rob.

Posted: Wed Apr 13, 2005 7:03 pm
by spacebiscuit
After a little investigation I have noticed that my emails composed with the 'imap_mail_compose' function differ slightly from other emails.

If I open the email once it has been sent to the server with a text editor the image part looks something like this......

/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYW
GDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/



However in the emails which contain attachment and do not crash my file viewer the email part looks like this:

begin 644 1.jpg
M_]C_X``02D9)1@`!`0```0`!``#_VP!#``4#!`0$`P4$!`0%!04&!PP(!P<'
M!P\+"PD,$0\2$A$/$1$3%AP7$Q0:%1$1&"$8&AT='Q\?$Q<B)"(>)!P>'Q[_
`
end


You'll notice that the 2nd piece of code has a begin and end around the binary part of the image encoding. This is the only difference I can idenitfy between the 2 emails.

I think I have to somehow work out how to add this in the compose email process. Any ideas anyone?

Thanks,

Rob Burne.