Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.01 KB | None | 0 0
  1. <?php
  2. /**
  3. * Simple example script using PHPMailer with exceptions enabled
  4. * @package phpmailer
  5. * @version $Id$
  6. */
  7.  
  8. require 'class.phpmailer.php';
  9.  
  10. try {
  11. $mail = new PHPMailer(true); //New instance, with exceptions enabled
  12.  
  13. $to = "saxena@designmaniac.in";
  14. $mail->AddAddress($to);
  15. $mail->From = $_POST['email'];
  16. $mail->FromName = $_POST['name_f'];
  17. $mail->Subject = "Admission Form";
  18.  
  19. $body = "<table>
  20. <tr>
  21. <th colspan='2'>Admission Form</th>
  22. </tr>
  23.  
  24. <tr>
  25. <td style='font-weight:bold'>Course :</td>
  26. <td>".$_POST['course']."</td>
  27. </tr>
  28.  
  29. <tr>
  30. <td style='font-weight:bold'>Payment Mode :</td>
  31. <td>".$_POST['p_mode']."</td>
  32. </tr>
  33.  
  34. <tr>
  35. <td style='font-weight:bold'>Payment options :</td>
  36. <td>".$_POST['p_option']."</td>
  37. </tr>
  38.  
  39. <tr>
  40. <td style='font-weight:bold'>First Name :</td>
  41. <td>".$_POST['name_f']."</td>
  42. </tr>
  43.  
  44. <tr>
  45. <td style='font-weight:bold'>Middle Name : </td>
  46. <td>".$_POST['name_m']."</td>
  47. </tr>
  48.  
  49. <tr>
  50. <td style='font-weight:bold'>Last Name : </td>
  51. <td>".$_POST['name_l']."</td>
  52. </tr>
  53.  
  54. <tr>
  55. <td style='font-weight:bold'>E-mail : </td>
  56. <td>".$_POST['email']."</td>
  57. </tr>
  58.  
  59. <tr>
  60. <td style='font-weight:bold'>Date of Birth : </td>
  61. <td>".$_POST['date']."</td>
  62. </tr>
  63.  
  64. <tr>
  65. <td style='font-weight:bold'>Gender : </td>
  66. <td>".$_POST['gender']."</td>
  67. </tr>
  68.  
  69. <tr>
  70. <td style='font-weight:bold'>Nationality : </td>
  71. <td>".$_POST['nationality']."</td>
  72. </tr>
  73.  
  74. <tr>
  75. <td style='font-weight:bold'>Address : </td>
  76. <td>".$_POST['address_line1']."</td>
  77. </tr>
  78.  
  79. <tr>
  80. <td style='font-weight:bold'>City : </td>
  81. <td>".$_POST['city']."</td>
  82. </tr>
  83.  
  84. <tr>
  85. <td style='font-weight:bold'>Zip Code : </td>
  86. <td>".$_POST['zip']."</td>
  87. </tr>
  88.  
  89. <tr>
  90. <td style='font-weight:bold'>State : </td>
  91. <td>".$_POST['state']."</td>
  92. </tr>
  93.  
  94. <tr>
  95. <td style='font-weight:bold'>Country : </td>
  96. <td>".$_POST['country']."</td>
  97. </tr>
  98.  
  99. <tr>
  100. <td style='font-weight:bold'>Mobile Number : </td>
  101. <td>".$_POST['mobile_number']."</td>
  102. </tr>
  103.  
  104. <tr>
  105. <td style='font-weight:bold'>Father/Mother First Name : </td>
  106. <td>".$_POST['fname_f']."</td>
  107. </tr>
  108.  
  109. <tr>
  110. <td style='font-weight:bold'>Father/Mother Middle Name : </td>
  111. <td>".$_POST['fname_m']."</td>
  112. </tr>
  113.  
  114. <tr>
  115. <td style='font-weight:bold'>Father/Mother Last Name : </td>
  116. <td>".$_POST['fname_l']."</td>
  117. </tr>
  118.  
  119. <tr>
  120. <td style='font-weight:bold'>Father/Mother Mobile No : </td>
  121. <td>".$_POST['mobile_number1']."</td>
  122. </tr>
  123.  
  124. <tr>
  125. <td style='font-weight:bold'>Qualification : </td>
  126. <td>".$_POST['qualification']."</td>
  127. </tr>
  128.  
  129. <tr>
  130. <td style='font-weight:bold'>University : </td>
  131. <td>".$_POST['university']."</td>
  132. </tr>
  133.  
  134. <tr>
  135. <td style='font-weight:bold'>Year : </td>
  136. <td>".$_POST['year']."</td>
  137. </tr>
  138.  
  139. <tr>
  140. <td style='font-weight:bold'>Qualification : </td>
  141. <td>".$_POST['qualification_2']."</td>
  142. </tr>
  143.  
  144. <tr>
  145. <td style='font-weight:bold'>University : </td>
  146. <td>".$_POST['university_2']."</td>
  147. </tr>
  148.  
  149. <tr>
  150. <td style='font-weight:bold'>Year : </td>
  151. <td>".$_POST['year_2']."</td>
  152. </tr>
  153.  
  154. <tr>
  155. <td style='font-weight:bold'>Qualification : </td>
  156. <td>".$_POST['qualification_3']."</td>
  157. </tr>
  158.  
  159. <tr>
  160. <td style='font-weight:bold'>University : </td>
  161. <td>".$_POST['university_3']."</td>
  162. </tr>
  163.  
  164. <tr>
  165. <td style='font-weight:bold'>Year : </td>
  166. <td>".$_POST['year_3']."</td>
  167. </tr>
  168.  
  169. <tr>
  170. <td style='font-weight:bold'>Discipline Information (School) : </td>
  171. <td>".$_POST['discipline']."</td>
  172. </tr>
  173.  
  174. <tr>
  175. <td style='font-weight:bold'>Discipline Information (Violation) : </td>
  176. <td>".$_POST['violation']."</td>
  177. </tr>
  178.  
  179. <tr>
  180. <td style='font-weight:bold'>12th Mark List : </td>
  181. <td>".$_POST['attachment1']."</td>
  182. </tr>
  183.  
  184. <tr>
  185. <td style='font-weight:bold'>12th Passing Certificate : </td>
  186. <td>".$_POST['attachment2']."</td>
  187. </tr>
  188.  
  189. <tr>
  190. <td style='font-weight:bold'>10th Mark List : </td>
  191. <td>".$_POST['attachment3']."</td>
  192. </tr>
  193.  
  194. <tr>
  195. <td style='font-weight:bold'>10th Passing Certificate : </td>
  196. <td>".$_POST['attachment4']."</td>
  197. </tr>
  198.  
  199. <tr>
  200. <td style='font-weight:bold'>Address Proof : </td>
  201. <td>".$_POST['attachment8']."</td>
  202. </tr>
  203.  
  204. <tr>
  205. <td style='font-weight:bold'>Photographs : </td>
  206. <td>".$_POST['attachment9']."</td>
  207. </tr>
  208.  
  209. <table>";
  210. $body = preg_replace('/\\\\/','', $body); //Strip backslashes
  211. $mail->MsgHTML($body);
  212.  
  213. $mail->IsSMTP(); // tell the class to use SMTP
  214. $mail->SMTPAuth = true; // enable SMTP authentication
  215. $mail->Port = 25; // set the SMTP server port
  216. //$mail->Host = "saxena@designmaniac.in"; // SMTP server
  217. //$mail->Username = "name@domain.com"; // SMTP server username
  218. //$mail->Password = "password"; // SMTP server password
  219.  
  220. $mail->IsSendmail(); // tell the class to use Sendmail
  221. $mail->AddReplyTo("saxena@designmaniac.in");
  222. $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  223. $mail->WordWrap = 80; // set word wrap
  224.  
  225.  
  226. // Check if at least one file is attached
  227. if(isset($_FILES["fileToUpload"]))){
  228.   // Check filetypes
  229.   $allowedFileTypes = ["jpg", "jpeg", "png", "gif", "pdf", "docx", "doc"];
  230.   // For each loop to check all uploaded file names
  231.   foreach($_FILES["fileToUpload"]["name"] as $key => $value ){
  232.     $extension = pathinfo($path, PATHINFO_EXTENSION);
  233.     if(!in_array($extension, $allowedFileTypes)){
  234.       throw new Exception("Extension {$extension} not allowed. Allowed extensions: " . implode( ", ", $allowedFileTypes));
  235.     }
  236.   }
  237.  
  238.   // Calculate total file size
  239.   $totalSize = 0;
  240.   $maxSize = 5 * 1024 * 1024;
  241.   foreach($_FILES["fileToUpload"]["size"] as $key => $value){
  242.     $totalSize += $value;
  243.   }
  244.   if($totalSize > $maxSize){
  245.       // Max file size of 5 mb
  246.       throw new Exception("Filesize is {$totalSize}, but the max size is {$maxSize}");
  247.   }
  248.  
  249.   // Add all attachments to the email
  250.   foreach($_FILES["filesToUpload"]["tmp_name"] as $key => $value){
  251.     $mail->AddAttachment($_FILES["fileToUpload"]["tmp_name"][$key], $_FILES["fileToUpload"]["name"][$key])''
  252.   }
  253. }
  254.  
  255.  
  256. $mail->IsHTML(true); // send as HTML
  257. $mail->Send();
  258. echo 'Thank You. Your form has been submitted';
  259. } catch (Exception $e) {
  260. echo $e->errorMessage();
  261. }
  262.  
  263. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement