ballouta Posted May 19, 2009 Share Posted May 19, 2009 Hello I searched on google for a contact form with an attachment option, i tried many scripts but i got error on many of them, some are restricted with a specific extension. Would you please provide a simple contact form + PHP script sample link? Many thanks Quote Link to comment Share on other sites More sharing options...
keha76 Posted May 19, 2009 Share Posted May 19, 2009 It shouldnt be very hard to modify an existing script to allow more extensions, wich scripts are you looking at? Quote Link to comment Share on other sites More sharing options...
ballouta Posted May 19, 2009 Author Share Posted May 19, 2009 Actually i deleted them all, still have this one which requires two files: include_once('Mail.php'); include_once('mime.php'); and i they were not attached with the script. I prefer a simple contact form with one attachment field thank you <?php $max_allowed_file_size = "100"; // 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 = "RecipietnEmail@hotmail.com"; $subject="An email with attachement is sent"; $from = "SenderEmail@hotmail.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."; } ?> Quote Link to comment Share on other sites More sharing options...
ballouta Posted May 19, 2009 Author Share Posted May 19, 2009 http://www.veign.com/code-view.php?type=web&codeid=62 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.