note 26609 deleted from ref.mail by kennyt

From: Date: Sun, 18 Jul 2004 17:43:26 +0000
Subject: note 26609 deleted from ref.mail by kennyt
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73541@lists.php.net to get a copy of this message
Note Submitter: kieran.huggins@rogers.com ---- Finally got MIME working with attachments and everything: The following is an example of a plaintext/html e-mail with attachments for the HTML code, I had to include the weird markup that outlook express 6 added when the message was sent, otherwise it wouldn't display properly. Send a copy of the message to yourself and copy the source. Also, the /n newlines are important, normal rules of HTML seem to go kinda wonky with e-mail... Experiment with your mailer and try different stuff. <?php // some local variables $from_name = "Sender Name"; $from_email = "sender@server.ca"; $to_name = "Recipient Name"; $to_email = "recipient@server.ca"; $subject = "Fantastic Subject"; // headers need to be in the correct order... $headers = "From: $from_name<$from_email>\n"; $headers .= "Reply-To: <$from_email>\n"; $headers .= "MIME-Version: 1.0\n"; // the following must be one line (post width too small) $headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"---- =MIME_BOUNDRY_main_message\"\n"; // $headers .= "X-Sender: $from_name<$from_email>\n"; $headers .= "X-Mailer: PHP4\n"; //mailer $headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal $headers .= "Return-Path: <$from_email>\n"; $headers .= "This is a multi-part message in MIME format.\n"; $headers .= "------=MIME_BOUNDRY_main_message \n"; $headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n"; //plaintext section begins $message = "------=MIME_BOUNDRY_message_parts\n"; $message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; $message .= "Content-Transfer-Encoding: quoted-printable\n"; $message .= "\n"; // your text goes here $message .= "blah blah -- plaintext version of the message\n"; $message .= "\n"; // html section begins $message .= "------=MIME_BOUNDRY_message_parts\n"; $message .= "Content-Type: text/html;\n charset=\"iso-8859-1\"\n"; $message .= "Content-Transfer-Encoding: quoted-printable\n"; $message .= "\n"; // your html goes here -- It didn't appear properly without // the weird markup that outlook added after sending $message .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"; $message .= "<HTML><BODY>\n"; $message .= "blah blah -- html version of the message\n"; // look ma, I'm referencing an img attachment (see below) // watch out for weird markup!!! $message .= "<IMG src=3D\"cid:some_picture\">\n"; $message .= "</BODY></HTML>\n"; $message .= "\n"; // this ends the message part $message .= "------=MIME_BOUNDRY_message_parts--\n"; $message .= "\n"; // now we add attachments (images, etc) $message .= "------=MIME_BOUNDRY_main_message\n"; $message .= "Content-Type: image/gif; \n name=\"some_picture.gif\"\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-ID: <some_picture>\n"; $message .= "\n"; // (truncated for space) $message .= "R0lGODlheAAZAKIHAMTExCQkJJOTk\n"; $message .= "eLo7wzDKSatVQ5R3u7dDUUjcZ34D\n"; $message .= "\n"; // etc...etc...etc... //message ends $message .= "------=MIME_BOUNDRY_main_message--\n"; // send the message :-) mail("$to_name<$to_email>", $subject, $message, $headers); ?> I hope this helps -- sorry for the long post! Kieran

« previous php.notes (#73541) next »