Advertisement
Guest User

Untitled

a guest
Sep 7th, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.34 KB | None | 0 0
  1. <?php
  2. //Settings
  3. $max_allowed_file_size = 2000; // size in KB
  4. $allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "png");
  5. $upload_folder = './uploads/'; //<-- this folder must be writeable by the script
  6.  
  7. $errors ='';
  8.  
  9. if(isset($_POST['email'])) {
  10. require_once "Mail.php"; //PEAR mail is already installed in our current environment
  11. require_once "Mail/mime.php";
  12.  
  13. $email_to = "awhite@atlanticpawnde.com"; //Enter the email you want to send the form to
  14. $email_subject = "Pawn Request"; // You can put whatever subject here
  15.  
  16. $host = "mail78.safesecureweb.com"; // The hostname of your mail server
  17. // If your email is with HostMySite, use the actual hostname of your mail server, for example:
  18. // SmarterMail: mailXX.safesecureweb.com OR win-mailXX.hostmanagement.net
  19. // OpenX-change: smtp.hostmanagement.net
  20. // Contact Support if you aren't sure what to enter here.
  21.  
  22. $username = "awhite@atlanticpawnde.com"; // A valid email address you have setup
  23. $from_address = "awhite@atlanticpawnde.com"; // If your mail is hosted with HostMySite this has to match the email address above
  24. $password = "Pawn.de10975"; // Password for the above email address
  25. $reply_to = "awhite@atlanticpawnde.com"; //Enter the email you want customers to reply to
  26. $port = "587"; // This is the default port. Try port 50 if this port gives you issues and your mail is hosted with HostMySite
  27.  
  28. //Get the uploaded file information
  29. $name_of_uploaded_file = basename($_FILES['image']['name']);
  30.  
  31. //get the file extension of the file
  32. $type_of_uploaded_file = substr($name_of_uploaded_file,
  33. strrpos($name_of_uploaded_file, '.') + 1);
  34.  
  35. $size_of_uploaded_file = $_FILES["image"]["size"]/1024;
  36.  
  37. function died($error) {
  38. // your error code can go here
  39. echo "We are very sorry, but there were error(s) found with the form you submitted. ";
  40. echo "These errors appear below.<br /><br />";
  41. echo $error."<br /><br />";
  42. echo "Please go back and fix these errors.<br /><br />";
  43. die();
  44. }
  45.  
  46. // Validate expected data exists
  47. if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['price']) || !isset($_POST['email']) || !isset($_POST['phone']) || !isset($_POST['message'])) {
  48. died('We are sorry, but there appears to be a problem with the form you submitted.');
  49. }
  50.  
  51. if($size_of_uploaded_file > $max_allowed_file_size )
  52. {
  53. $errors .= "n Size of file should be less than $max_allowed_file_size";
  54. }
  55.  
  56. $allowed_ext = false;
  57. for($i=0; $i<sizeof($allowed_extensions); $i++)
  58. {
  59. if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
  60. {
  61. $allowed_ext = true;
  62. }
  63. }
  64.  
  65. if(!$allowed_ext)
  66. {
  67. $errors .= "n The uploaded file is not supported file type. ".
  68. " Only the following file types are supported: ".implode(',',$allowed_extensions);
  69. }
  70.  
  71. if(empty($errors))
  72. {
  73. //copy the temp. uploaded file to uploads folder
  74. $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
  75. $tmp_path = $_FILES["image"]["tmp_name"];
  76.  
  77. if(is_uploaded_file($tmp_path))
  78. {
  79. if(!copy($tmp_path,$path_of_uploaded_file))
  80. {
  81. $errors .= 'n error while copying the uploaded file';
  82. }
  83. }
  84.  
  85. $first_name = $_POST['first_name']; // required
  86. $last_name = $_POST['last_name']; // required
  87. $price = $_POST['price']; // not required
  88. $email = $_POST['email']; // required
  89. $mobile = $_POST['phone']; // not required
  90. $message = $_POST['message']; // required
  91.  
  92. $error_message = "";
  93. $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
  94. if(!preg_match($email_exp,$email)) {
  95. $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  96. }
  97. $string_exp = "/^[A-Za-z .'-]+$/";
  98. if(!preg_match($string_exp,$first_name)) {
  99. $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  100. }
  101. if(!preg_match($string_exp,$last_name)) {
  102. $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  103. }
  104. if(strlen($message) < 2) {
  105. $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  106. }
  107. if(strlen($error_message) > 0) {
  108. died($error_message);
  109. }
  110. $email_message = "Form details below.nn";
  111. function clean_string($string) {
  112. $bad = array("content-type","bcc:","to:","cc:","href");
  113. return str_replace($bad,"",$string);
  114. }
  115. $email_message .= "First Name: ".clean_string($first_name)."n";
  116. $email_message .= "Last Name: ".clean_string($last_name)."n";
  117. $email_message .= "Price: ".clean_string($price)."n";
  118. $email_message .= "Email: ".clean_string($email)."n";
  119. $email_message .= "Phone Number: ".clean_string($mobile)."n";
  120. $email_message .= "Comments: ".clean_string($message)."n";
  121.  
  122. $message = new Mail_mime();
  123. $message->addAttachment($path_of_uploaded_file);
  124. $body = $message->get();
  125.  
  126. // This section creates the email headers
  127. $auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password, 'port' => $port);
  128. $headers = array('From' => $from_address, 'To' => $email_to, 'Subject' => $email_subject, 'Reply-To' => $reply_to);
  129.  
  130. // This section send the email
  131. $smtp = Mail::factory('smtp', $auth);
  132. $mail = $smtp->send($email_to, $headers, $email_message, $body)
  133.  
  134.  
  135. if (PEAR::isError($mail)) {?>
  136. <!-- include your own failure message html here -->
  137. <?php
  138. header('location:fail.htm');
  139. ?>
  140. <!-- Uncomment the line below to see errors with sending the message -->
  141. <!--<?php echo("<p>". $mail->getMessage()."</p>"); ?> -->
  142.  
  143. <?php } else { ?>
  144. <?php
  145. header('location:success.htm');
  146. ?>
  147. <?php } } ?>
  148.  
  149. <form action="Send_Test.php" enctype="multipart/form-data" method="post">
  150.  
  151. <div class="form-group">
  152. <label for="first_name" class="uname">
  153. <i class="field_icon ion-android-contact"></i>First Name</label>
  154. <input id="first_name" name="first_name" required type="text" placeholder="" class="form-control" required="required">
  155. </div>
  156.  
  157. <div class="form-group">
  158. <label for="last_name" class="uname">
  159. <i class="field_icon ion-android-contact"></i>Last Name</label>
  160. <input id="last_name" name="last_name" required type="text" placeholder="" class="form-control" required="required">
  161. </div>
  162.  
  163. <div class="form-group">
  164. <label for="email">
  165. <i class="field_icon ion-android-mail"></i>Email Address</label>
  166. <input type="email" name="email" id="email" class="form-control" required="required" >
  167. </div>
  168.  
  169. <div class="form-group">
  170. <label for="phone"><i class="field_icon ion-ios-telephone "></i>Contact Number</label>
  171. <input type="text" class="form-control" id="phone" data-mask="(999) 999-9999" name="phone" placeholder="" required="required">
  172. </div>
  173. </div>
  174.  
  175. <div class="form-group">
  176. <label for="price">
  177. <i class= "field_icon ion-pricetag"></i>Amount Needed ($)</label>
  178. <input id="price" name="price" class="form-control" required type="number" min="1" step="any" >
  179. </div>
  180. </div>
  181.  
  182. <div class="form-group">
  183. <label for="message">
  184. <i class="field_icon ion-compose"></i>Describe your item</label>
  185. <textarea name="message" class="form-control" rows="3" id="message" required="required" >
  186. </textarea>
  187. </div>
  188.  
  189.  
  190. <div class="form-group">
  191. <label class="control-label">Upload Photos (required)</label>
  192. <input name="image" id="input-22" type="file" class="file" accept="image/*" multiple=true data-preview-file-type="text" data-preview-class="bg-warning">
  193. </div>
  194.  
  195.  
  196. <div class="form-group">
  197. <input type="submit" value="submit" class="btn btn-lg btn-block btn-primary" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement