The following code will allow you to send an email, with a file attachment without the need for a 3rd party library. This code assumes that you already have the upload and form fully operational.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
function XMail( $from, $fromname, $to, $subj, $text, $filename) { //Open our file, rb = windows machine, you may need to change this to r for linux $f = fopen($filename,"rb"); //let's get a uniqueidentifier $un = strtoupper(uniqid(time())); //Set the from name and address $head = "From: $fromname <$from>\n"; //set who we are sending this to $head .= "To: $to\n"; //set the subject $head .= "Subject: $subj\n"; //just for s's and giggles $head .= "X-Mailer: PHPMail Tool\n"; //set the reply to address $head .= "Reply-To: $from\n"; //now we set our mime types, content types, and encoding $head .= "Mime-Version: 1.0\n"; $head .= "Content-Type:multipart/mixed;"; $head .= "boundary=\"----------".$un."\"\n\n"; $zag = "------------".$un."\nContent-Type:text/html;\n"; $zag .= "Content-Transfer-Encoding: 8bit\n\n$text\n\n"; $zag .= "------------".$un."\n"; $zag .= "Content-Type: application/octet-stream;"; //pop in the filename for good measures $zag .= "name=\"".basename($filename)."\"\n"; //now attach it $zag .= "Content-Transfer-Encoding:base64\n"; $zag .= "Content-Disposition:attachment;"; $zag .= "filename=\"".basename($filename)."\"\n\n"; $zag .= chunk_split(base64_encode(fread($f, filesize($filename))))."\n"; //this will return true or false if the send was successful return @mail("$to", "$subj", $zag, $head); } |






