RE: [PHP] Re: MIME help needed please...

From: Date: Wed, 26 Feb 2003 08:14:50 +0000
Subject: RE: [PHP] Re: MIME help needed please...
Groups: php.general 
Request: Send a blank email to php-general+get-137197@lists.php.net to get a copy of this message
I just sorted a similar problem I was having. Basically make sure that the file your trying to send is Chmod'ed so that the mail() can actually execute not just read. I was having the same problem where any email I was attaching a file to (in this case a PDF) was attaching the file fine but only the headers so I was receiving a PDF type document but with no information in it. I chmodded the file to 7777 and it works fine. I also made use of this script: // uses mime_mail() class from functions.php $msg = "This is a PDF e-mail"; $attachment = fread(fopen("db/webopman.pdf", "r"), filesize("db/webopman.pdf")); $mail = new mime_mail(); $mail->from = "info@webpage.co.uk"; $mail->headers = "Errors-To: steve@webpage.co.uk"; $mail->to = $email; $mail->subject = "Thanks for downloading our attachment"; $mail->body = $msg; $mail->add_attachment("$attachment", "webopman.pdf", "application/pdf"); $mail->send(); Calling this class: /* * Class mime_mail * Original implementation by Sascha Schumann <sascha@schumann.cx> * Modified by Tobias Ratschiller <tobias@dnet.it>: * - General code clean-up * - separate body- and from-property * - killed some mostly un-necessary stuff */ class mime_mail { var $parts; var $to; var $from; var $headers; var $subject; var $body; /* * void mime_mail() * class constructor */ function mime_mail() { $this->parts = array(); $this->to = ""; $this->from = ""; $this->subject = ""; $this->body = ""; $this->headers = ""; } /* * void add_attachment(string message, [string name], [string ctype]) * Add an attachment to the mail object */ function add_attachment($message, $name = "", $ctype = "application/octet-stream") { $this->parts[] = array ( "ctype" => $ctype, "message" => $message, "encode" => $encode, "name" => $name ); } /* * void build_message(array part= * Build message parts of an multipart mail */ function build_message($part) { $message = $part[ "message"]; $message = chunk_split(base64_encode($message)); $encoding = "base64"; return "Content-Type: ".$part[ "ctype"]. ($part[ "name"]? "; name = \"".$part[ "name"]. "\"" : ""). "\nContent-Transfer-Encoding: $encoding\n\n$message\n"; } /* * void build_multipart() * Build a multipart mail */ function build_multipart() { $boundary = "b".md5(uniqid(time())); $multipart = "Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME encoded message.\n\n--$boundary"; for($i = sizeof($this->parts)-1; $i >= 0; $i--) { $multipart .= "\n".$this->build_message($this->parts[$i]). "--$boundary"; } return $multipart.= "--\n"; } /* * void send() * Send the mail (last class-function to be called) */ function send() { $mime = ""; if (!empty($this->from)) $mime .= "From: ".$this->from. "\n"; if (!empty($this->headers)) $mime .= $this->headers. "\n"; if (!empty($this->body)) $this->add_attachment($this->body, "", "text/html"); $mime .= "MIME-Version: 1.0\n".$this->build_multipart(); mail($this->to, $this->subject, "", $mime); } }; // end of class ?> Hope this solves the issue. Steve Jackson Web Developer Viola Systems Ltd. http://www.violasystems.com stephen.jackson@violasystems.com Mobile +358 50 343 5159 > -----Original Message----- > From: Manuel Lemos [mailto:mlemos@acm.org] > Sent: 26. helmikuuta 2003 3:51 > To: php-general@lists.php.net > Subject: [PHP] Re: MIME help needed please... > > > Hello, > > On 02/23/2003 08:01 PM, Shawn McKenzie wrote: > > I got this from the user contributed notes in the php.net > manual. It > > seems to work fine most of the time, but Eudora and Pegasus users > > either get mangled attachments or no attachments. > > > > Can anyone see a problem (most files are zip, but sometimes > tar.gz or > > sit) I tried using Content-Type: application/zip with the same > > results. I'm thinking it is some issue with the headers, > > content-types, boundaries or something. Or maybe > Pegasus/Eudora don't > > understand MIME or base64 (doubtful)??? > > It could be one of many bugs of the mail() function. > > You may want to try this class for composing and sending MIME > messages > as it works around some of those bugs: > http://www.phpclasses.org/mimemessage -- Regards, Manuel Lemos -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#137197) next »