To send a letter with an attachment I use the following function:

function sendMailAttachment($mailTo, $from, $subject, $text, $file = false) { $separator = "---"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "From: $from\nReply-To: $from\n"; if($file) { $headers .= "Content-Type: multipart/mixed; boundary=\"$separator\""; $bodyMail = "--$separator\n"; $bodyMail .= "Content-type: text/html; charset='utf-8'\n"; $bodyMail .= "Content-Transfer-Encoding: quoted-printable"; $bodyMail .= "Content-Disposition: attachment; filename==?utf-8?B?".base64_encode(basename($file))."?=\n\n"; $bodyMail .= $text."\n"; $bodyMail .= "--$separator\n"; $fileRead = fopen($file, "r"); $contentFile = fread($fileRead, filesize($file)); fclose($fileRead); $bodyMail .= "Content-Type: application/octet-stream; name==?utf-8?B?".base64_encode(basename($file))."?=\n"; $bodyMail .= "Content-Transfer-Encoding: base64\n"; $bodyMail .= "Content-Disposition: attachment; filename==?utf-8?B?".base64_encode(basename($file))."?=\n\n"; $bodyMail .= chunk_split(base64_encode($contentFile))."\n"; $bodyMail .= "--".$separator ."--\n"; } else { $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $bodyMail = $text; } $result = mail($mailTo, $subject, $bodyMail, $headers); return $result; } 

The fact is that the file name is randomly generated (random number). The variable $file contains the full path to the file. The letter comes with a file name, for example 3211955146559 . How to change the file name to, for example, attachment ?

0