Please help me with submit form code

  • allie4218
  • Born
  • Born
  • allie4218
  • Posts: 1

Post 3+ Months Ago

I am trying to get my form to submit a a file attachment (.doc, .pdf) along with the form info in an email. Can someone help me with the code?

Here is the page: http://www.plmed.com/submitresume_test.html

I did this as an attempt to use PEAR in my submit code.

Here is the submit email script (please help ! I have a client meeting with this guy in 1 hour!!):

Code: [ Select ]
<?php
$max_allowed_file_size = "3000"; // this is size in KB
list($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file) = GetUploadedFileInfo();
if(!Validate($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file, $max_allowed_file_size)) {
exit();
}
LoadUploadedFile($name_of_uploaded_file);
$path_of_uploaded_file = "uploads/" . $name_of_uploaded_file;

include_once('Mail.php');
include_once('mime.php');

ComposeMail($path_of_uploaded_file);


//////////////////// Functions ////////////////////////

function GetUploadedFileInfo() {
$file_info[] = basename($_FILES['uploaded_file']['name']);
$file_info[] = substr($file_info[0], strrpos($file_info[0], '.') + 1);
$file_info[] = $_FILES["uploaded_file"]["size"]/1024;
return $file_info;
}


function Validate($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file, $max_allowed_file_size) {
if($size_of_uploaded_file>$max_allowed_file_size ) {
     echo "Size of file is greater than" . $max_allowed_file_size . " KB. <a href='attachment_email_form.html'>Click Here to upload a smaller sized file.</a>";
     return false;
}
$allowed_extension = array("jpg", "jpeg", "gif", "bmp");
for($i=0; $i<sizeof($allowed_extension); $i++) {
$allowed_extension[$i] = strtoupper($allowed_extension[$i]);
}
$type_of_uploaded_file = strtoupper($type_of_uploaded_file);
if(!(in_array(strtoupper($type_of_uploaded_file),$allowed_extension))) {
echo "You have uploaded a file with an extension of " . $type_of_uploaded_file . " . This type is not allowed. Please upload a file with allowed image extensions like jpg, jpeg, bmp, gif. <a href='attachment_email_form.html'>Click Here to upload a file with allowed extension.</a>";
return false;
}
return true;
}


function LoadUploadedFile($name_of_uploaded_file) {
move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], "uploads/" . $name_of_uploaded_file);
return true;
}


function ComposeMail($name_of_uploaded_file) {
$name = $_POST['name'];
$user_message = $_POST['message'];
$to = "alliepappas@yahoo.com";
$subject="An email with attachement is sent";
$from = "allie@alliepappas.com";
$text = "A user" . $name . "has sent you this message and an attachment: " . $user_message;
$message = new Mail_mime();
$message->setTXTBody($text);
$message->addAttachment($name_of_uploaded_file);
$body = $message->get();
$extraheaders = array("From"=>$from, "Subject"=>$subject);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);
echo "Your Email with attachment was sent.";
}
?>
  1. <?php
  2. $max_allowed_file_size = "3000"; // this is size in KB
  3. list($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file) = GetUploadedFileInfo();
  4. if(!Validate($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file, $max_allowed_file_size)) {
  5. exit();
  6. }
  7. LoadUploadedFile($name_of_uploaded_file);
  8. $path_of_uploaded_file = "uploads/" . $name_of_uploaded_file;
  9. include_once('Mail.php');
  10. include_once('mime.php');
  11. ComposeMail($path_of_uploaded_file);
  12. //////////////////// Functions ////////////////////////
  13. function GetUploadedFileInfo() {
  14. $file_info[] = basename($_FILES['uploaded_file']['name']);
  15. $file_info[] = substr($file_info[0], strrpos($file_info[0], '.') + 1);
  16. $file_info[] = $_FILES["uploaded_file"]["size"]/1024;
  17. return $file_info;
  18. }
  19. function Validate($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file, $max_allowed_file_size) {
  20. if($size_of_uploaded_file>$max_allowed_file_size ) {
  21.      echo "Size of file is greater than" . $max_allowed_file_size . " KB. <a href='attachment_email_form.html'>Click Here to upload a smaller sized file.</a>";
  22.      return false;
  23. }
  24. $allowed_extension = array("jpg", "jpeg", "gif", "bmp");
  25. for($i=0; $i<sizeof($allowed_extension); $i++) {
  26. $allowed_extension[$i] = strtoupper($allowed_extension[$i]);
  27. }
  28. $type_of_uploaded_file = strtoupper($type_of_uploaded_file);
  29. if(!(in_array(strtoupper($type_of_uploaded_file),$allowed_extension))) {
  30. echo "You have uploaded a file with an extension of " . $type_of_uploaded_file . " . This type is not allowed. Please upload a file with allowed image extensions like jpg, jpeg, bmp, gif. <a href='attachment_email_form.html'>Click Here to upload a file with allowed extension.</a>";
  31. return false;
  32. }
  33. return true;
  34. }
  35. function LoadUploadedFile($name_of_uploaded_file) {
  36. move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], "uploads/" . $name_of_uploaded_file);
  37. return true;
  38. }
  39. function ComposeMail($name_of_uploaded_file) {
  40. $name = $_POST['name'];
  41. $user_message = $_POST['message'];
  42. $to = "alliepappas@yahoo.com";
  43. $subject="An email with attachement is sent";
  44. $from = "allie@alliepappas.com";
  45. $text = "A user" . $name . "has sent you this message and an attachment: " . $user_message;
  46. $message = new Mail_mime();
  47. $message->setTXTBody($text);
  48. $message->addAttachment($name_of_uploaded_file);
  49. $body = $message->get();
  50. $extraheaders = array("From"=>$from, "Subject"=>$subject);
  51. $headers = $message->headers($extraheaders);
  52. $mail = Mail::factory("mail");
  53. $mail->send($to, $headers, $body);
  54. echo "Your Email with attachment was sent.";
  55. }
  56. ?>
Moderator Remark: added [code] tags
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 73 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.