NYCPHP Meetup

NYPHP.org

[nycphp-talk] Emailing files from server

Rick Retzko rick at click-rick.net
Fri Sep 7 15:55:10 EDT 2007


Help please with setting up a function to email a specific file from a
specific directory located on my server to a customer.
 
Issue: My customer wants to have an xls file with specific info from their
website eMailed to him on demand.  I pulled a script from php.net, but I
can't seem to get it to grab the file.  The emailing works, but not the
attachment.
 
The key clip of the script is:
if($attachments!==false){
  for($i=0;$i<count($attachments);$i++){
   if(is_file($attachments[$i]["file"])){
    #File for Attachment
 
$file_name=substr($attachments[$i]["file"],(strrpos($attachments[$i]["file"]
,"/")+1));
    
    $handle=fopen($attachments[$i]["file"],'rb');
    $f_contents=fread($handle,filesize($attachments[$i]["file"]));
    $f_contents=chunk_split(base64_encode($f_contents));
    $f_type=filetype($attachments[$i]["file"]);
    fclose($handle);
    
    #Attachment
    $msg.="--".$mime_boundary.$eol;
    $msg.="Content-Type: ".$attachments[$i]["content-type"].";
name=\"".$file_name."\"".$eol;
    $msg.="Content-Transfer-Encoding: base64".$eol;
    $msg.="Content-Description: ".$file_name.$eol;
    $msg.="Content-Disposition: attachment;
filename=\"".$file_name."\"".$eol.$eol;
    $msg.=$f_contents.$eol.$eol;
   }
  }
 
where I've set up '$attachments' as:
$attachments = Array(  Array("file"=>"/students.xls",
"content_type"=>"application/x-msexcel "));
 
Thanks for any help you can offer!
 
Best Regards - 
 
Rick
============
MFR Holdings, LLC
rick at click-rick.net
201.755.4083
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20070907/7062437a/attachment.html>


More information about the talk mailing list