[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 [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Send attachments with an email (Sample Code for you lot :))
I see this question asked here all the time, and recently had to implement it. Ugh, apologies for the crappy formatting. *slap.outlook* Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Send attachments with an email (Sample Code for you lot :))
*makes a note to develop a fully functional, system independent Slap class* Slap.setStrength(getMaxStrength()); Slap.setTarget(getLocation(Microsoft Outlook)); Slap.slap; *bows* Plutarck Jason Murray [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I see this question asked here all the time, and recently had to implement it. Ugh, apologies for the crappy formatting. *slap.outlook* Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Send attachments with an email (Sample Code for you lot :))
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=viewcodeid=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:[EMAIL PROTECTED]] Sent: Monday, May 21, 2001 11:34 PM To: '[EMAIL PROTECTED]' 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 [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]