I have a custom PHP form that was encoded about 3 years ago. It was created to email all messages, including docx files, and worked like a charm. Only since this year, the client notices that users complain about sending an error form that allows them to upload their resume. Troubleshooting found that this only happens with SOME .docx files. We have a ton of .docx files that have been uploaded and emailed in order. Thus, it is either: 1. a change in the .docx encoding or something unfamiliar with 2. Users must somehow damage their .docx files.
I searched for any evidence on how to change the code for the .docx files and found nothing. My code seems to be the best practice for uploading multiple files, even .docx files. To make sure that I send my send-mail.php file and ask if anyone sees something that would allow all of the file formats listed and some .docx to send FINE, but some .docx files delay the script and do not work on the "If (OK) {" line, that is, an error sending mail. Thanks in advance for any help.
UPDATE: It seems that it does not work with documents saved in the "Word 2016." format. . What do I need to do with my code below to get it working, as well as Word 2016 files
if(isset($_FILES) ) {
$allowedExtensions = array("pdf","doc","docx","gif","jpeg","jpg","png","rtf","txt","");
$files = array();
foreach($_FILES as $name=>$file) {
$file_name = $file['name'];
$temp_name = $file['tmp_name'];
$file_type = $file['type'];
$path_parts = pathinfo($file_name);
$ext = $path_parts['extension'];
if(!in_array($ext,$allowedExtensions)) {
die("Your file type is not allowed. Must be only pdf, txt, doc, docx, gif , jpeg, jpg, png, or rtf. Use backspace to go back.");
}
$server_file = "/home/content/25/9264325/html/wp-content/uploads/files/$path_parts[basename]";
move_uploaded_file($temp_name,$server_file);
array_push($files,$server_file);
}
$to = "xxxx@gmail.com";
$from = $email;
$subject ="NEW EMPLOYMENT APPLICATION";
$headers = "From: Cxxxxxxs \r\nReply-To: ".$from;
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\r\nMIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
$headers .= " boundary=\"{$mime_boundary}\"\r\n\r\n";
$message ="\r\n\r\n--{$mime_boundary}\r\n";
$message .="Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$message .="Content-Transfer-Encoding: base64\r\n\r\n" . $msg . "\r\n\r\n";
foreach($files as $file) {
$aFile = fopen($file,"rb");
$data = fread($aFile,filesize($file));
fclose($aFile);
$data = chunk_split(base64_encode($data));
$message .= "\r\n--{$mime_boundary}\r\n";
$message .= "Content-Type: {$file_type};\r\n";
$message .= " name=\"{$file_name}\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= "Content-Disposition: attachment;\r\n";
$message .= "filename=\"{$file_name}\"\r\n";
$message .= $data . "\r\n";
$message .= "--{$mime_boundary}--\r\n";
}
$ok = mail($to, $subject, $message, $headers);
if ($ok) {
header('Location: http://www.xxxxx.com/thank-you/');
} else {
echo "<p>mail could not be sent!</p>";
}
die();
}