MIME types

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
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

MIME types

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You need image/jpeg

obiously subtype here should be set to "jpeg" and i'd guess type will be TYPEIMAGE
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post 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.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Post 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.
Post Reply