mail function in php on godaddy host server doesn't send attachment i've tried to add the script on another server it worked very well. the problem starts to show up after I installed wordpress on the server so i had to create a php file in the wp-content/themes/ and i called it in the wordpress.. i created a folder called "uploads" beside that script to add the uploaded files into it then sends it to email.. it doesn't read it or upload the files in it..
i want to mention again that i added the same script in other host server with a folder called "uploads" in the same directory and it worked very well.. anybody have an idea how to solve this?
if(isset($_FILES) && (bool) $_FILES) { $AllowedExtensions = ["jpeg","jpg","png", null]; $files = []; $server_file = []; foreach($_FILES as $name => $file) { $file_name = $file["name"]; $file_temp = $file["tmp_name"]; foreach($file_name as $key) { $path_parts = pathinfo($key); $extension = strtolower($path_parts["extension"]); if(!in_array($extension, $AllowedExtensions)) { die("Extension not allowed"); } $server_file[] = "uploads/{$path_parts["basename"]}"; } for($i = 0; $i<count($file_temp); $i++) { move_uploaded_file($file_temp[$i], $server_file[$i]); } } $to = "John doe <myemail@gmail.com>"; // <-- Your Valid Email goes HERE $from = "abcabc@example.com"; $dte= date(); $subject ="Work Order $dte"; $message = $body_msg; // $message = trim(strip_tags($body_msg)); $headers = "From: $from"; $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= " MIME-Version: 1.0 " . "Content-Type: multipart/mixed; " . " boundary=\"{$mime_boundary}\""; $message = "This is a multi-part message in MIME format. " . "--{$mime_boundary} " . "Content-Type: text/html; charset=\"iso-8859-1\" " . "Content-Transfer-Encoding: 7bit " . $message . " "; $message .= "--{$mime_boundary} "; for($i = 0; $i<count($server_file); $i++) { $afile = fopen($server_file[$i],"rb"); $data = fread($afile,filesize($server_file[$i])); fclose($afile); $data = chunk_split(base64_encode($data)); $name = $file_name[$i]; $message .= "Content-Type: {\"application/octet-stream\"}; " . " name=\"$name\" " . "Content-Disposition: attachment; " . " >filename=\"$name\" " . "Content-Transfer-Encoding: base64 " . $data . " "; $message .= "--{$mime_boundary} "; } if(mail($to, $subject, $message, $headers)) { echo "<h2 style='text-align: center'>mail sent to $to!</h2>"; } else { echo "<p>mail could not be sent!</p>";enter code here } }