Suppose there is an array of $ file names of the following type:
Array ( [0] => asd.txt [1] => asdd.txt [2] => asddd.txt )
This array is passed to the send_mail function, which processes it and sends an email with several attachments. This is in theory, but in practice only the last investment comes. Here is the function:
function send_mail($email, $subject, $msg, $from, $file) { $boundary = "--" . md5(uniqid(time())); $headers = "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n"; $headers .= "From: $from\n"; $multipart = "--$boundary\n"; $multipart .= "Content-Type: text/html; charset=utf-8\n"; $multipart .= "Content-Transfer-Encoding: Quot-Printed\n\n"; $multipart .= "$msg\n\n"; foreach ($file as $key => $value) { $fp = fopen($value, "r"); $file = fread($fp, filesize($value)); $message_part = "--$boundary\n"; $message_part .= "Content-Type: application/octet-stream\n"; $message_part .= "Content-Transfer-Encoding: base64\n"; $message_part .= "Content-Disposition: attachment; filename=\"$value\"\n\n"; $message_part .= chunk_split(base64_encode($file)) . "\n"; } $multipart .= $message_part . "--$boundary--\n"; mail($email, $subject, $multipart, $headers); }
The question is, accordingly, where is the dog buried?