Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Settings
- $max_allowed_file_size = 2000; // size in KB
- $allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "png");
- $upload_folder = './uploads/'; //<-- this folder must be writeable by the script
- $errors ='';
- if(isset($_POST['email'])) {
- require_once "Mail.php"; //PEAR mail is already installed in our current environment
- require_once "Mail/mime.php";
- $email_to = "awhite@atlanticpawnde.com"; //Enter the email you want to send the form to
- $email_subject = "Pawn Request"; // You can put whatever subject here
- $host = "mail78.safesecureweb.com"; // The hostname of your mail server
- // If your email is with HostMySite, use the actual hostname of your mail server, for example:
- // SmarterMail: mailXX.safesecureweb.com OR win-mailXX.hostmanagement.net
- // OpenX-change: smtp.hostmanagement.net
- // Contact Support if you aren't sure what to enter here.
- $username = "awhite@atlanticpawnde.com"; // A valid email address you have setup
- $from_address = "awhite@atlanticpawnde.com"; // If your mail is hosted with HostMySite this has to match the email address above
- $password = "Pawn.de10975"; // Password for the above email address
- $reply_to = "awhite@atlanticpawnde.com"; //Enter the email you want customers to reply to
- $port = "587"; // This is the default port. Try port 50 if this port gives you issues and your mail is hosted with HostMySite
- //Get the uploaded file information
- $name_of_uploaded_file = basename($_FILES['image']['name']);
- //get the file extension of the file
- $type_of_uploaded_file = substr($name_of_uploaded_file,
- strrpos($name_of_uploaded_file, '.') + 1);
- $size_of_uploaded_file = $_FILES["image"]["size"]/1024;
- function died($error) {
- // your error code can go here
- echo "We are very sorry, but there were error(s) found with the form you submitted. ";
- echo "These errors appear below.<br /><br />";
- echo $error."<br /><br />";
- echo "Please go back and fix these errors.<br /><br />";
- die();
- }
- // Validate expected data exists
- if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['price']) || !isset($_POST['email']) || !isset($_POST['phone']) || !isset($_POST['message'])) {
- died('We are sorry, but there appears to be a problem with the form you submitted.');
- }
- if($size_of_uploaded_file > $max_allowed_file_size )
- {
- $errors .= "n Size of file should be less than $max_allowed_file_size";
- }
- $allowed_ext = false;
- for($i=0; $i<sizeof($allowed_extensions); $i++)
- {
- if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
- {
- $allowed_ext = true;
- }
- }
- if(!$allowed_ext)
- {
- $errors .= "n The uploaded file is not supported file type. ".
- " Only the following file types are supported: ".implode(',',$allowed_extensions);
- }
- if(empty($errors))
- {
- //copy the temp. uploaded file to uploads folder
- $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
- $tmp_path = $_FILES["image"]["tmp_name"];
- if(is_uploaded_file($tmp_path))
- {
- if(!copy($tmp_path,$path_of_uploaded_file))
- {
- $errors .= 'n error while copying the uploaded file';
- }
- }
- $first_name = $_POST['first_name']; // required
- $last_name = $_POST['last_name']; // required
- $price = $_POST['price']; // not required
- $email = $_POST['email']; // required
- $mobile = $_POST['phone']; // not required
- $message = $_POST['message']; // required
- $error_message = "";
- $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
- if(!preg_match($email_exp,$email)) {
- $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
- }
- $string_exp = "/^[A-Za-z .'-]+$/";
- if(!preg_match($string_exp,$first_name)) {
- $error_message .= 'The First Name you entered does not appear to be valid.<br />';
- }
- if(!preg_match($string_exp,$last_name)) {
- $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
- }
- if(strlen($message) < 2) {
- $error_message .= 'The Comments you entered do not appear to be valid.<br />';
- }
- if(strlen($error_message) > 0) {
- died($error_message);
- }
- $email_message = "Form details below.nn";
- function clean_string($string) {
- $bad = array("content-type","bcc:","to:","cc:","href");
- return str_replace($bad,"",$string);
- }
- $email_message .= "First Name: ".clean_string($first_name)."n";
- $email_message .= "Last Name: ".clean_string($last_name)."n";
- $email_message .= "Price: ".clean_string($price)."n";
- $email_message .= "Email: ".clean_string($email)."n";
- $email_message .= "Phone Number: ".clean_string($mobile)."n";
- $email_message .= "Comments: ".clean_string($message)."n";
- $message = new Mail_mime();
- $message->addAttachment($path_of_uploaded_file);
- $body = $message->get();
- // This section creates the email headers
- $auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password, 'port' => $port);
- $headers = array('From' => $from_address, 'To' => $email_to, 'Subject' => $email_subject, 'Reply-To' => $reply_to);
- // This section send the email
- $smtp = Mail::factory('smtp', $auth);
- $mail = $smtp->send($email_to, $headers, $email_message, $body)
- if (PEAR::isError($mail)) {?>
- <!-- include your own failure message html here -->
- <?php
- header('location:fail.htm');
- ?>
- <!-- Uncomment the line below to see errors with sending the message -->
- <!--<?php echo("<p>". $mail->getMessage()."</p>"); ?> -->
- <?php } else { ?>
- <?php
- header('location:success.htm');
- ?>
- <?php } } ?>
- <form action="Send_Test.php" enctype="multipart/form-data" method="post">
- <div class="form-group">
- <label for="first_name" class="uname">
- <i class="field_icon ion-android-contact"></i>First Name</label>
- <input id="first_name" name="first_name" required type="text" placeholder="" class="form-control" required="required">
- </div>
- <div class="form-group">
- <label for="last_name" class="uname">
- <i class="field_icon ion-android-contact"></i>Last Name</label>
- <input id="last_name" name="last_name" required type="text" placeholder="" class="form-control" required="required">
- </div>
- <div class="form-group">
- <label for="email">
- <i class="field_icon ion-android-mail"></i>Email Address</label>
- <input type="email" name="email" id="email" class="form-control" required="required" >
- </div>
- <div class="form-group">
- <label for="phone"><i class="field_icon ion-ios-telephone "></i>Contact Number</label>
- <input type="text" class="form-control" id="phone" data-mask="(999) 999-9999" name="phone" placeholder="" required="required">
- </div>
- </div>
- <div class="form-group">
- <label for="price">
- <i class= "field_icon ion-pricetag"></i>Amount Needed ($)</label>
- <input id="price" name="price" class="form-control" required type="number" min="1" step="any" >
- </div>
- </div>
- <div class="form-group">
- <label for="message">
- <i class="field_icon ion-compose"></i>Describe your item</label>
- <textarea name="message" class="form-control" rows="3" id="message" required="required" >
- </textarea>
- </div>
- <div class="form-group">
- <label class="control-label">Upload Photos (required)</label>
- <input name="image" id="input-22" type="file" class="file" accept="image/*" multiple=true data-preview-file-type="text" data-preview-class="bg-warning">
- </div>
- <div class="form-group">
- <input type="submit" value="submit" class="btn btn-lg btn-block btn-primary" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement