Posts this Month

March 2010
M T W T F S S
« Feb   Apr »
1234567
891011121314
15161718192021
22232425262728
293031  

Archived Posts

Categories

Tearing my hair out

I like the LAMP development platform. It’s cheap and very powerful although in corporations everything seems to be heading .NET.

I taught myself PHP from a book a while ago. I was an Oracle DBA at one point so the MySQL was easy. So I wrote a few utilities for my home Intranet and a Portfolio management tool for work. I find coding relaxing when I don’t have deadlines to meet so I have been enjoying building some internal sites for my own use. Call me weird.

However, I decided to have a go at a mailing list manager. All went OK until I decided to put an inline logo at the top of the EMails as an afterthought. Boy what a problem that is. I can’t get it to work properly. It displays the logo fine but underneath it is the filename of the file and it is clickable as well. Not like the ones I get when I am sent them.

Anyone now how to do this in PHP. Here is my simple test code.

$mail_logo = ‘Porn.jpg’;

$to = ‘LordT@MyDomain.com’;
$subject = ‘EMail with header’;

$file = fopen($mail_logo,’rb’);
$data = fread($file,filesize($mail_logo));
fclose($file);
$data = chunk_split(base64_encode($data));

$headers = “From: Sender@MyDomain.com\r\nReply-To: Sender@MyDomain.com\r\n”;
$headers .= “MIME-Version: 1.0\r\n”;

$boundary = md5(uniqid(time()));

$headers .= “Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n”;

$message = “–$boundary\r\n”;
$message .= “Content-Type: image/jpg;\n name=\”{$mail_logo}\”\n”;
$message .= “Content-Disposition: inline;\n filename=\”{$mail_logo}\”\n”;
$message .= “Content-Transfer-Encoding: base64\n\n”;
$message .= “$data\n\n”;

$message .= “–$boundary\r\n”;
$message .= “Content-Type: text/plain; charset=ISO-8859-1\n”;

$message .= “\n\nThis is the plain text version\nLine 2″;

$mail_sent = @mail( $to, $subject, $message, $headers );

It sends it fine. Just won’t get rid of that pesky filename. Anyone know anything out there. I’ve heard the Internet is a great source of information.