"; // Who the email is from $sendfile['email_subject'] = "File : %f (%s bytes)"; // The Subject of the email (%f will be file name, %s size) $sendfile['email_message'] = "File name : %f\nSize: %s bytes\nDownloaded from : %l\n\n%t"; // Message along with attachment (%f: file name, %s: size, %l: original location, %t: free text) $sendfile['email_to'] = "you@yourblog.com"; // Default value of recipient's email when nothing specified $sendfile['file_dir'] = "/home/user/you/sendfile/files"; // Directory in which sent files will be mirrored first. Create this directory and chmod it 777 (make it writeable) $sendfile['file_delete'] = 1; // Default behaviour of the script once the file has been sent by email. Delete it (1) or keep it on server (0) $sendfile['file_log'] = "sendfile.log"; // Log file in which dates and URL of files sent are stored /*********************************** * END CONFIG * Do not modify below, unless you know * what you are doing ***********************************/ $sendfile['remote'] = stripslashes(init('remote')); $sendfile['local'] = stripslashes(init('local')); $sendfile['deletefile'] = init('deletefile'); $sendfile['dest'] = init('dest'); $sendfile['text'] = stripslashes(init('text')); $sendfile['log'] = stripslashes(init('log')); $sendfile['action'] = init('action'); $sendfile['bintext'] = init('bintext'); html(); if (!$sendfile['remote'] and $sendfile['action']) { print '

ERROR : You did not specify any file to send ! Try again !

'; $sendfile['action'] = ''; } switch ($sendfile['action']) { case 'mirror': mirrorfile($sendfile['remote']); break; case 'send': sendfile($sendfile['local']); default: printform(); } function init($in='') { return @$_GET[$in]?@$_GET[$in]:@$_POST[$in]; } function logsend() { global $sendfile; $log=fopen($sendfile['file_log'],"a"); $stamp = date("Y/m/d G:i:s"); $msg = "$stamp :\n\tFile ${sendfile['remote']}\n\tSent to ${sendfile['dest']}\n\n"; fputs($log,$msg); fclose($log); } function sendfile($input) { global $sendfile; /* PREPARE VARIABLES */ if (!$sendfile['dest']) $sendfile['dest'] = $sendfile['email_to']; if ($sendfile['log']) print $sendfile['log']; print "

Sending file to " . $sendfile['dest'] . " ...

"; $sendfile['email_subject'] = str_replace ('%f',basename($input),$sendfile['email_subject']); $sendfile['email_subject'] = str_replace ('%s',filesize($input),$sendfile['email_subject']); $sendfile['email_message'] = str_replace ('%f',basename($input),$sendfile['email_message']); $sendfile['email_message'] = str_replace ('%s',filesize($input),$sendfile['email_message']); $sendfile['email_message'] = str_replace ('%l',$sendfile['remote'],$sendfile['email_message']); $sendfile['email_message'] = str_replace ('%t',$sendfile['text'],$sendfile['email_message']); /* PREPARE MAIL HEADERS */ $headers = "From: ".$sendfile['email_from']; $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . @$sendfile['email_message'] . "\n\n" . "-- \nFile sent with PHP Send File By Email\nhttp://frenchfragfactory.net/ozh/my-projects/php-send-file-by-email-sendmail-attachment/\n" . "(c) Ozh 2005 - http://planetozh.com\n\n" ; /* PREPARE ATTACHMENT */ $fileatt = basename($input) ; $fileatt_type = "application/octet-stream"; $file = fopen($input,"r${sendfile['bintext']}"); $data = fread($file,filesize($input)); fclose($file); $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt};\n" . " name=\"{$fileatt}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; /* SEND FILE */ $ok = @mail($sendfile['dest'], $sendfile['email_subject'], $email_message, $headers); if($ok) { echo '

File successfully sent!

'; logsend(); } else { echo('

ERROR : could not send email.

'); } if($sendfile['deletefile'] and ($input != __FILE__) ) { $ok=unlink($input); if ($ok==FALSE) { echo '

ERROR : could not delete file from server.

'; } else { echo '

File successfully deleted.

'; } } } function mirrorfile($url) { global $sendfile; if (!$sendfile['local']) $sendfile['local'] = basename($url); $log = "

Mirroring file $url ...

"; print $log; $msg = ''; // open source file $hfici=@fopen($url,"r${sendfile['bintext']}"); // woks fine ? if($hfici==FALSE){ // No :/ $msg="ERROR : couldn't read source file $url."; } else { // Yes : create target file $hfico=@fopen($sendfile['file_dir'] . '/' . $sendfile['local'],"w${sendfile['bintext']}"); // works fine ? if($hfico==FALSE){ // No :/ $msg="ERROR : couldn't locally write file"; } else { // Yes : read remote and write local while($buf=fread($hfici,1024)){ fwrite($hfico, $buf); } fclose($hfici); fclose($hfico); } } if ($msg) { print "

$msg

"; printform(); } else { $log2 = "

File locally mirrored !

Preparing mail and attachment ...

"; print $log2; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; //print ''; print '
'; print << document.form_send.submit(); JS; } } function printform() { global $sendfile; if ($sendfile['file_delete']) { $checked_del = 'checked'; $checked_keep = ''; } else { $checked_del = ''; $checked_keep = 'checked'; } $_this = basename(__FILE__); print <<
Send a File

URL of file to send

Rename this file

Binary or Text file

Delete locally mirrored file

Send file to

Additionnal message

 

PHP Send File By Email by Ozh

HTML; } function html() { print << PHP Send File
HTML; } ?>