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.

3 comments to Tearing my hair out

  • Total silence from the ranks.

  • Lord T

    So the Internet is not as good as I thought then.

    Al Gore has screwed me again.

  • hello :)

    tell ya what … i havent a clue but have only …only just found out about php (no, stop laughing) ive made a start in the form of a download lol Well its something!
    I may not know now but i will find out !
    my take me a while but…
    i will do it!

    Taught yourself hmmm not just me then !
    Like it!
    What do i get if i do it????
    Can i choose hmmmmm…..
    (ive got something in mind already)
    :)

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>