Hello everyone,
I'm using the code below in order to add an attachement to an email built from a form.
The problem is that the filename of the attachement found in the email remains the one of the temporary file made during the upload.
How could I make sure that it's the real filename of the file that will appear in the email?
Thanks a lot to the ones who will help.
Cheers
I'm using the code below in order to add an attachement to an email built from a form.
The problem is that the filename of the attachement found in the email remains the one of the temporary file made during the upload.
How could I make sure that it's the real filename of the file that will appear in the email?
Thanks a lot to the ones who will help.
Cheers
Code:
for($i=0; $i <= sizeof($file_fieldname); $i++ ) {
if ($_FILES[$file_fieldname[$i]]['name'] != "") {
$file_name = $_FILES[$file_fieldname[$i]]['name'];
$file_type = $_FILES[$file_fieldname[$i]]['type'];
$file_tmp_name = $_FILES[$file_fieldname[$i]]['tmp_name'];
$file_cnt = "";
$f=@fopen($file_tmp_name, "rb");
if (!$f) continue;
while($f && !feof($f))
$file_cnt .= fread($f, 4096);
fclose($f);
if (!strlen($file_type)) $file_type="application/octet-stream";
if ($file_type == 'application/x-msdownload') $file_type = "application/octet-stream";
$message .= "--" . $separator . $br;
$message .= "Content-Type: " . $file_type . ";" . $br;
$message .= "name=\"" .$file_name . "\"" . $br;
$message .= "Content-Transfer-Encoding: base64" . $br;
$message .= "Content-Disposition: attachment;" . $br;
$message .= "filename=\"" . $file_name . "\"" . $br . $br;
$message .= chunk_split(base64_encode($file_cnt));
}
}