PHP Classes

Attach file

Recommend this page to a friend!

      SMTP  >  All threads  >  Attach file  >  (Un) Subscribe thread alerts  
Subject:Attach file
Summary:Attach file
Messages:3
Author:xak2
Date:2010-01-27 22:16:04
Update:2010-02-08 15:32:12
 

  1. Attach file   Reply   Report abuse  
Picture of xak2 xak2 - 2010-01-27 22:16:04
How to attach file. After adding header for construct and modify sendHeaders, attached file will send, but this is emty (28byts?!)

  2. Re: Attach file   Reply   Report abuse  
Picture of xak2 xak2 - 2010-01-27 22:45:55 - In reply to message 1 from xak2
<?
require_once 'mail_class.php';

$file = fopen('test.pdf','rb');
$data = fread($file,filesize('test.pdf'));
fclose($file);
$data = chunk_split(base64_encode($data));
$headers = array(
'Content-Type: application/pdf; name="Test.pdf"',
'Content-Disposition: attachment; filename="Test.pdf"',
'Content-Transfer-Encoding: base64',
$data
);

if (new Mail('[email protected]','Test subject','<h2>Mail is send!</h2>', $headers)) {
echo 'Mail is sent -> OK';
}
else {
echo 'Mail is not sent';
}
?>

$this->headers = &$headers; for construct and

for ($i = 0; $i < count($this->headers); $i++) {
$this->sendCommand($this->headers[$i]);
}
for sendHeaders

  3. Re: Attach file   Reply   Report abuse  
Picture of Ivan Priorov Ivan Priorov - 2010-02-08 15:32:12 - In reply to message 2 from xak2
Hi!
To send files you need change the class.
A simple change of the two functions will not work.
You must use the MIME TYPE, which has a different structure of the headers and body...