dumdumsareyum Posted March 6, 2009 Share Posted March 6, 2009 I am trying to send an email with an attachment. The attachment file type should be pdf or doc. I check the file submitted in my form for this extension and then email it. It is working good except the file shows up with no extension. I tried appending the file extension I had found earlier to check the file type, but it didn't work. I think my problem may lie in that my attachment type is listed as "application", but I don't know what the appropriate attachment type would be as the part to send the attachment was a copy past job Help please? if($_POST) { //check if a file was uploaded move to uploads if(sizeof($_FILES > 0)) { $file_ext = strrchr($_FILES['resume']['name'], '.'); $file_ext = strtolower($file_ext); if($file_ext == ".pdf" || $file_ext == ".doc" || $file_ext == ".docx") { $tempfile = $_FILES['resume']['tmp_name']; $origin = $_FILES['resume']['name']; $date = date(mdY); $time = date(His); //send email ini_set(sendmail_from, "chriscernoch@slantgraphics.com"); // Additional headers $headers .= 'To: <exampleemail@example>' . "\r\n"; $fileatt = "$tempfile"; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $fileatt_name = "resumeD$dateT$time$file_ext"; // Filename that will be used for the file as the attachment $email_from = "examplememail@example.com"; // Who the email is from $email_subject = "Resume Received"; // The Subject of the email $email_txt = "A resume as been received from the Houston Controls website"; // Message that the email has in it $email_to = "exampleemail@example.com"; // Who the email is too $headers = "From: ".$email_from; $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message . "\n\n"; $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; if( @mail($email_to, $email_subject, $email_message, $headers)) { echo "<p class='message'>Your resume has been received. You may also <a href='a href=$path/jobs/application.php'>submit an application</a> at this time if you have not already done so.</p>"; } else { echo "<p class='message'>We were unable to receive your resume at this time. Please try again later or call our office at 713.672.1200.</p>"; } } //end of file file_ext else { $message="type";} } //end of if sizeof(files) Quote Link to comment https://forums.phpfreaks.com/topic/148260-solved-email-attachment/ Share on other sites More sharing options...
JonnoTheDev Posted March 6, 2009 Share Posted March 6, 2009 Use PEAR::Mail_mime to send emails with attachments, not the mail() function. It is not designed for this. I see this same issue posted over and over. http://pear.php.net/package/Mail_Mime Quote Link to comment https://forums.phpfreaks.com/topic/148260-solved-email-attachment/#findComment-778351 Share on other sites More sharing options...
dumdumsareyum Posted March 6, 2009 Author Share Posted March 6, 2009 thanks but I just realized adding the file extension back does work, I had just forgotten to upload my changes to the server. oops! Quote Link to comment https://forums.phpfreaks.com/topic/148260-solved-email-attachment/#findComment-778370 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.