I've trying to send an email with two attachments. The problem is that only the first attachment gets sent. I've tried swapping the order but same result. Anyone have any help here?
// Sending Email message to applicant
$to = "$memEmail";
$from = "me <info@mydomain.ca>";
$subject = "Applciation Approved";
$message = "Thank you for your submission. The course is $course.";
$fileatt = "Cert.pdf";
$fileatt2 = "Letter.pdf";
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt2,'rb');
$data2 = fread($file,filesize($fileatt2));
fclose($file);
// Generate a boundary string
$data = chunk_split(base64_encode($data));
$data2 = chunk_split(base64_encode($data2));
$num = md5( time() );
// Add the overall headers with type shown for a file attachment
$hdr = "From:$from\r\n";
$hdr .= "MIME-Version: 1.0\r\n";
$hdr .= "Content-Type: multipart/mixed; ";
$hdr .= "boundary=$num\r\n";
$hdr .= "--$num\r\n";
// this adds the text section
$hdr .= "Content-Type: text/plain\r\n";
$hdr .= "Content-Transfer-Encoding: 8bit\r\n\n";
$hdr .= "$message\r\n";
$hdr .= "--$num\n";
// this adds the first attachment
$hdr .= "Content-Type: $att_type; ";
$hdr .= "name=\"$fileatt2\"\r\n";
$hdr .= "Content-Transfer-Encoding: base64\r\n";
$hdr .= "Content-Disposition: attachment; ";
$hdr .= "filename=\"$fileatt2\"\r\n\n";
$hdr .= "$data2\r\n";
$hdr .= "--$num--";
// add the next attachment
$hdr .= "Content-Type: $att_type; ";
$hdr .= "name=\"$fileatt\"\r\n";
$hdr .= "Content-Transfer-Encoding: base64\r\n";
$hdr .= "Content-Disposition: attachment; ";
$hdr .= "filename=\"$fileatt\"\r\n\n";
$hdr .= "$data\r\n";
$hdr .= "--$num--";
mail($to, $subject, $message, $hdr); // send the e-mail