RE: [PHP] mailto function to attach a photo

2001-08-28 Thread Lawrence . Sheed

You're probably going to need a mime class - Manuel Lemos makes a good one,
then send as a mime attachment.

http://freshmeat.net/projects/mimemessageclass/

Some sample code below that I use (and a mime class).

Example.php
?
if (!isset($SEND_MIME_LOADED)) {
require mimeclass.php;
}

$mymessage = new Mail(); 
$mymessage-from = $emailfrom; 
$mymessage-to = $emailto; 
$mymessage-subject = $emailfromname sent a picture to you from
shanghaiguide.com; 
$mymessage-headers[Reply-To] = $emailfrom; 
$mymessage-headers[X-Extra-Header] = Pointless Header v3.0; 
$mymessage-body = $emailfromname sent you a picture from the
ShanghaiGuide.com site\n . 
\n.
http://www.Shanghaiguide.com\n\n;.
The Shanghai Guide - The real guide to Shanghai
Life\n\nLive Chat, Thousands of Pictures, Classifieds, Message Forum and
more...;
$mymessage-attachments[0] = $DOCUMENT_ROOT.$pic; 
$mymessage-Send();

?



mimeclass.php
?php

//Abort on re-entry...
if ($SEND_MIME_LOADED==1){
exit;
}

$SEND_MIME_LOADED=1;



//Main Code

/*
Uses sendmail to send the mail, mimencode to do the MIME  
encoding, and zip to automatically zip attachments. 

Contacting the author(s): 
Brought to you by the team at Sequoia Softworks, http://www.sequoiasoft.com 
Feel free to contact [EMAIL PROTECTED] and tell us how you like it! 
(Or to complain bitterly, report bugs, or suggest new features.) 

Known shortcomings/bugs: 
o guessMIMEType()only knows about a few MIME types. You can expand this as  
  you need. 
o $mime_boundary in the Send() method should be randomly generated, but it  
  isn't likely to ever hurt anything in its current form 

Example: 
 require(Mail.phtml); 
 $mymessage = new Mail(); 
 $mymessage-from = [EMAIL PROTECTED]; 
 $mymessage-to = [EMAIL PROTECTED]; 
 $mymessage-subject = This is your lucky day; 
 $mymessage-headers[Reply-To] = [EMAIL PROTECTED]; 
 $mymessage-headers[X-Extra-Header] = Pointless Header v3.0; 
 $mymessage-body = Doesn't it feel good to get mail?\nEspecially with
files  
 attached!\n; 
 $mymessage-attachments[0] = tarball.tar.gz; 
 $mymessage-attachments[1] = images/smiling_countenance.gif; 
 $mymessage-attachments[2] = /usr/share/reference/jargondict.html; 
 $mymessage-attachments[3] = ./core; 
 $mymessage-attachments[4] = /etc/passwd;  //naughty naughty!! 
 $mymessage-ZipAttachments(your_files.zip); //uncomment this to zip all  
   //the attachments into one
big  
   //attachment. 
 $mymessage-Send(); 
*/ 
class Mail { 
var $from; //The sender 
var $to; //The recipient 
var $subject; //The subject line 
var $headers; //A hash of additional headers (headername = headervalue)

var $zipname; //The name of the file the attachments are zipped into 
  //($zipname == false if attachments are to be sent  
  //individually) 
var $attachments; //An array of files to attach 
var $body; //The body text of the message 
 
//Mail constructor: initializes vars to default values. 'Nuff said. 
function Mail() { 
$this-from = ; 
$this-to = ; 
$this-subject = ; 
$this-headers = array(); 
$this-zipname = false; 
$this-attachments = array(); 
$this-body = ; 
} 
 
//Auxiliary method, used to guess a file's MIME type 
//based on its extension. Doesn't know about too many 
//extensions right now 
function guessMIMEType($filename) { 
//GUESS MIME TYPE 
$filename = basename($filename); 
if(strrchr($filename,.) == false) { 
return(application/octet-stream); 
} 
 
$ext = strrchr($filename,.); 
switch($ext) { 
case .gif: 
return image/gif; 
break; 
case .gz: 
return application/x-gzip; 
case .htm: 
case .html: 
return text/html; 
break; 
case .jpg: 
return image/jpeg; 
break; 
case .tar: 
return application/x-tar; 
break; 
case .txt: 
return text/plain; 
break; 
case .zip: 
return application/zip; 
break; 
default: 
return application/octet-stream; 
break; 
} 
} 

//Cute little convenience method. Supply it with a filename to  
//zip attachments to, or supply it with false if attachments are 
//sent individually 
function ZipAttachments($name) { 
$this-zipname = $name; 
} 

//The workhorse method, does the actually 

RE: [PHP] mailto function to attach a photo

2001-08-28 Thread Jason Murray

I could never get MIME classes and the like to work, so I rolled 
my own, so to speak. It was posted here a while ago, but I have
a copy on my web server @ home:

http://planetkiller.shadow.net.au/mime-php.txt

--
Jason Murray
[EMAIL PROTECTED]
Web Developer, Melbourne IT
Work now, freak later!

-- 
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]