I try to send 2 or 3 PDF files generated by FPDF class as attachments within the same email using PHP mail function but every time only one attachment sent. I tried to edit my code many times but it is still not working. I want to know what's the wrong with my code if it is working properly with the first attachment and it is not working with the other attachments?
// attachment
// $files is an array
$separator = md5(time());
$eol = PHP_EOL;
for ($i = 0; $i < count($files); $i++)
{
$filename = $files[$i].".pdf";
$filepath = 'https://www.mywebsite.com/pdf/index.php?tcode='.$tcode[$i];
// to specify the attachment file path to send */
$content = file_get_contents($filepath);
$attachment = chunk_split(base64_encode($content));
$reply_message .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$reply_message .= "Content-Transfer-Encoding: base64".$eol;
$reply_message .= "Content-Disposition: attachment".$eol.$eol;
$reply_message .= $attachment.$eol;
$reply_message .= "--".$separator."--";
}
mail($email_reply, $reply_subject, $reply_message, $headers1);