Question : Rmail add file attachment how-to ?

Hi experts,
I'm trying to use Rmail for a web form ... actually it works well until I add file attachment ... I think I just dunno  how to make it correct .. :(

Please help me with the attachment process. On Rmail I can simply use this to attach file:
@require_once('Rmail.php');
$mail = new Rmail();
$mail->addAttachment(new fileAttachment('test.pdf'));
$result  = $mail->send(array('my@email.com'));

But that's only if the file 'test.pdf' is already uploaded on the server.

Right now I'm adding this to the form
Attachment:<input name="fileatt" type="file" />

On the submit form I add this:
$fileatt = $_FILES['fileatt']['tmp_name'];

and on the Rmail variables:
$mail->addAttachment(new fileAttachment($fileatt));

But I know that's not the correct way since it display errors...

Please help me with the correct PHP codes to attach a file on the form ... Thanks.

Answer : Rmail add file attachment how-to ?

Something like this, give it a go:
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:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
<?php  

$file_field = "fileatt";
if (!isset($_FILES[$file_field])) {
  echo "file's field is not set.";
  exit();
}

if ($_FILES[$file_field]["error"] != 0) {
  echo "upload error.";
  exit();
}

if ($_FILES[$file_field]["name"] == "") {
  echo "name is empty.";
  exit();
}

$file_basename = basename($_FILES[$file_field]["name"]);
if ($file_basename != "") {
  echo "file basename is empty.";
  exit();
}


$time = time();
while (file_exists("/tmp/{$time}")) {
  $time++;
}

if (!mkdir("/tmp/{$time}")) {
  echo "mkdir failed.";
  exit();
}

$file_path = "/tmp/{$time}/{$file_basename}";
if (!@move_uploaded_file($_FILES[$file_field]['tmp_name'], $file_path) {
  echo "move_uploaded_file failed.";
  exit();
}






// use $file_path for the mailer








// After the mailer, remove the file and the path:
unlink($file_path);
rmdir("/tmp/{$time}");

?>
Random Solutions  
 
programming4us programming4us