RE: [PHP] Send attachments with an email (Sample Code for you lot :))
| From: | Jason Lotito | Date: | Tue, 22 May 2001 04:52:43 +0000 |
| Subject: | RE: [PHP] Send attachments with an email (Sample Code for you lot :)) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-53810@lists.php.net to get a copy of this message | ||
Jason,
I hope you don't mind, but I posted your script in my Code Depository
located here:
http://www.newbienetwork.net/phpcodems.php?as=viewcode&id=24
You are given credit, and hopefully it can get some use out of it.
Either way, thanks for showing us. =)
Jason Lotito
www.NewbieNetwork.net
> -----Original Message-----
> From: Jason Murray [mailto:Jason.Murray@melbourneit.com.au]
> Sent: Monday, May 21, 2001 11:34 PM
> To: 'php-general@lists.php.net'
> Subject: [PHP] Send attachments with an email (Sample Code
> for you lot :))
>
>
> Hi folks,
>
> I see this question asked here all the time, and recently had
> to implement it. Every class and solution I downloaded and
> tried to use failed for one reason or another, so I threw
> together this, instead.
>
> Advatages:
> * Quick :)
> * It's a function, so you can call it from most places if
> it's include()'d.
>
> Disadvantages:
> * Quick, so probably buggy :)
> * I haven't put in any facility for sending a HTML version
> of your mail text
> yet. We don't send HTML mails @ Melbourne IT, so it wasn't needed.
>
> Usage:
>
> mailattachments((DestinationAddress), (Subject), (Email
> Body), (File Attachment Info),
> (Extra Headers));
>
> "File Attachment Info" is an array:
>
> $fileattach[] = array("filename" =>
> "/full/path/to/file/on/your/system",
> "mimetype" => "mimetype/here");
>
> And the code guts:
>
> <?
> Function mailattachments( $to, $subject, $body, $attacharray,
> $extraheaders)
> {
> // Generate a unique boundary
> $mail_boundary = md5(uniqid(time()));
>
> // MIME-compliant headers
> $mailheaders = $extraheaders
> ."MIME-Version: 1.0\r\n"
> ."Content-type:
> multipart/mixed;boundary=\"$mail_boundary\"\r\n"
> ."\r\n"
> ."This is a multipart MIME message\r\n"
> ."\r\n";
>
> // Body. The part that gets displayed as the message:
> $mailbody = "--$mail_boundary\r\n"
> ."Content-type: text/plain;charset=us-ascii\r\n"
> ."Content-transfer-encoding: 8bit\r\n"
> ."\r\n"
> .$body
> ."\r\n";
>
> // Now, do the attachments
> for ($i = 0; $i < count($attacharray); $i++ )
> {
> $fp = fopen($attacharray[$i][filename], "r");
> $file = fread($fp, filesize($attacharray[$i][filename]));
>
> $file = base64_encode($file); //
> BASE64-encoded.
> Text. Nice.
> $file = chunk_split($file); //
> Now in handy
> bite-sized 76-char chunks.
> $filename = basename($attacharray[$i][filename]);
>
> $mailbody .= "--$mail_boundary\r\n"
> ."Content-type:
> ".$attacharray[$i][mimetype]."; name=".$filename."\r\n"
> ."Content-transfer-encoding: base64\r\n"
> ."\r\n"
> .$file
> ."\r\n"
> ."\r\n";
> }
>
> // End of mail
> $mailbody .= "--$mail_boundary--";
>
> mail($to, $subject, $mailbody, $mailheaders);
> }
> ?>
>
> Hope this helps someone out there...
>
> Jason
>
> --
> Jason Murray
> jasonm@melbourneit.com.au
> Web Developer, Melbourne IT
> "What'll Scorpy use wormhole technology for?"
> 'Faster pizza delivery.'
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail:
> php-general-help@lists.php.net To contact the list
> administrators, e-mail: php-list-admin@lists.php.net
>
>