[PHP] sending mail with attachment problems

2004-01-27 Thread tony
Hi,

i'm trying to send emails with attachment but i get an error
at $file = fread($fp, $att_size);
and i don't understand why, any help is appreciated.
code is below

 $subject = $_REQUEST['subject'];
 $cc  = $_REQUEST['cc'];
 $from= $_REQUEST['from'];
 $message = $_REQUEST['text'];
 $att = $_FILES['attachment'];
 $filename = /home/prog/www/phpmail.txt;

 $handle = fopen ($filename, r);

  $fp   = fopen($att_name, r);
  $file = fread($fp,$att_size);
  $file = chunk_split(base64_encode($file));
  $num  = md5( time() );

  $hdr  = From:$from\r\n;
  $hdr .= CC:$cc\r\n;
  $hdr .= MIME-Version: 1.0\r\n;
  $hdr .= Content-type: multipart/mixed; ;
  $hdr .= boundary=$num \r\n;
  $hdr .= --$num\r\n;

  $hdr .= Content-type: text/plain\r\n;
  $hdr .= Content-Transfer-Encoding: 8bit\r\n\n;
  $hdr .= $message\r\n;
  $hdr .= --$num\n;

  $hdr .= Content-type: $att_type; ;
  $hdr .= name=\$att_name\\r\n;
  $hdr .= Content-Transfer-Encoding: base64\r\n;
  $hdr .= Content-Disposition: attachment; ;
  $hdr .= filename=\$att_name\\r\n\n;
  $hdr .= $file\r\n;
  $hdr .= --$num--;

  do{
   $data = fread($handle, 128);
   if (strlen($data) == 0) {
break;
   }
   mail($data,$subject,,$hdr);
   print done to $data  with attachment;

  }while(true);
fclose($handle);

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] sending mail with attachment problems

2004-01-27 Thread memoimyself
Hello Tony,

On 27 Jan 2004 at 16:47, tony wrote:

 Hi,
 
 i'm trying to send emails with attachment but i get an error (...)

I haven't even had a look at your code, but sending e-mails with attachments can be 
quite tricky, so I suggest that instead of trying to re-invent the wheel you use 
Richard 
Heyes's excellent (and free) HTML Mime Mail class available at 
http://www.phpguru.org/mime.mail.html .

Cheers,

Erik

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php