elis Posted September 15, 2008 Share Posted September 15, 2008 Here is my full script (it's supposed to email the document after it's been uploaded) <?php /* Test emailing ability */ require_once '../startups.php'; if ( isset($_POST['submit_candidate']) ){ if ( is_uploaded_file($_FILES['resume_doc']['tmp_name']) ){ $resume_doc = fopen($_FILES['resume_doc']['tmp_name'], 'rb'); $resume_filetype = $_FILES['resume_doc']['type']; $resume_filename = $_FILES['resume_doc']['name']; } else { $resume_doc = null; $resume_filetype = null; $resume_filename = null; } if(!empty($resume_doc)){ $ext = end(explode('.',$resume_doc)); if($ext = "doc"){ $type ="doc"; } else $type = "docx"; $data = chunk_split(base64_encode($resume_doc)); $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x"; $headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // The message $message = "Line 1\nLine 2\nLine 3"; // In case any of our lines are larger than 70 characters, we should use wordwrap() $message = wordwrap($message, 70); $message .= "--{$mime_boundary}\n" . "Content-Type: $resume_filetype;\n" . " name=\"$resume_filename\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; // Send mail('email@emailplace.com','Test Subject',$message, $headers); } echo "mail sent and $type"; } else { echo "<form id=\"new\" action=\"sendmail.php\" method=\"post\" enctype=\"multipart/form-data\"> <div class=\"field-label\"><label for=\"resume_doc\">Formatted Word Resume</label>:</div> <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1000000\" /> <input id=\"resume_doc\" name=\"resume_doc\" type=\"file\" /> <br> <input type=\"submit\" name=\"submit_candidate\" value=\"Submit\" /> <input type=\"button\" value=\"Reset\"/></form>"; } ?> and I receive this error: Warning: base64_encode() expects parameter 1 to be string, resource given in /www/atest/sendmail.php on line 27 The email is sent however the attachment isn't. I'm not familiar with the mail() function at all. Can anyone spot what I've done wrong? Quote Link to comment Share on other sites More sharing options...
ratcateme Posted September 15, 2008 Share Posted September 15, 2008 $resume_doc is a file handler should that be $resume_filename? Scott. Quote Link to comment Share on other sites More sharing options...
elis Posted September 15, 2008 Author Share Posted September 15, 2008 That fixed it. Thanks! Quote Link to comment 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.