Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.16 KB | None | 0 0
  1. <?php
  2.  
  3. $formConfigFile = file_get_contents("rd-mailform.config.json");
  4. $formConfig = json_decode($formConfigFile, true);
  5.  
  6. date_default_timezone_set('Etc/UTC');
  7.  
  8. try {
  9. require './phpmailer/PHPMailerAutoload.php';
  10.  
  11. $recipients = $formConfig['recipientEmail'];
  12.  
  13. preg_match_all("/([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)/", $recipients, $addresses, PREG_OFFSET_CAPTURE);
  14.  
  15. if (!count($addresses[0])) {
  16. die('MF001');
  17. }
  18.  
  19. function getRemoteIPAddress() {
  20. if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  21. return $_SERVER['HTTP_CLIENT_IP'];
  22.  
  23. } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  24. return $_SERVER['HTTP_X_FORWARDED_FOR'];
  25. }
  26. return $_SERVER['REMOTE_ADDR'];
  27. }
  28.  
  29. if (preg_match('/^(127\.|192\.168\.)/', getRemoteIPAddress())) {
  30. die('MF002');
  31. }
  32.  
  33. $template = file_get_contents('rd-mailform.tpl');
  34.  
  35. if (isset($_POST['form-type'])) {
  36. switch ($_POST['form-type']){
  37. case 'contact':
  38. $subject = 'Un Test à été réalisé';
  39. break;
  40. case 'subscribe':
  41. $subject = 'Subscribe request';
  42. break;
  43. case 'order':
  44. $subject = 'Order request';
  45. break;
  46. default:
  47. $subject = 'Un Test à été réalisé';
  48. break;
  49. }
  50. }else{
  51. die('MF004');
  52. }
  53.  
  54. if (isset($_POST['email'])) {
  55. $template = str_replace(
  56. array("<!-- #{FromState} -->", "<!-- #{FromEmail} -->"),
  57. array("Email:", $_POST['email']),
  58. $template);
  59. }
  60.  
  61. if (isset($_POST['phone'])) {
  62. $template = str_replace(
  63. array("<!-- #{MessageState} -->", "<!-- #{MessageDescription} -->"),
  64. array("Phone:", $_POST['phone']),
  65. $template);
  66. }
  67.  
  68. if (isset($_POST['proprietaire'])) {
  69. $template = str_replace(
  70. array("<!-- #{InfoState} -->", "<!-- #{InfoDescription} -->"),
  71. array("proprietaire:", $_POST['proprietaire']),
  72. $template);
  73. }
  74.  
  75.  
  76.  
  77. if (isset($_POST['commune'])) {
  78. $template = str_replace(
  79. array("<!-- #{CommuneState} -->", "<!-- #{CommuneDescription} -->"),
  80. array("Commune:", $_POST['commune']),
  81. $template);
  82. }
  83.  
  84. if (isset($_POST['chauffage'])) {
  85. $template = str_replace(
  86. array("<!-- #{TypeChauffageState} -->", "<!-- #{TypeChauffageDescription} -->"),
  87. array("Chauffage:", $_POST['chauffage']),
  88. $template);
  89. }
  90.  
  91. if (isset($_POST['situation'])) {
  92. $template = str_replace(
  93. array("<!-- #{SituationState} -->", "<!-- #{SituationDescription} -->"),
  94. array("Situation:", $_POST['situation']),
  95. $template);
  96. }
  97.  
  98. if (isset($_POST['last-name'])) {
  99. $template = str_replace(
  100. array("<!-- #{LastNameState} -->", "<!-- #{LastNameDescription} -->"),
  101. array("Prenom:", $_POST['last-name']),
  102. $template);
  103. }
  104.  
  105. if (isset($_POST['name'])) {
  106. $template = str_replace(
  107. array("<!-- #{NameState} -->", "<!-- #{NameDescription} -->"),
  108. array("Nom:", $_POST['name']),
  109. $template);
  110. }
  111.  
  112. if (isset($_POST['address'])) {
  113. $template = str_replace(
  114. array("<!-- #{AddressState} -->", "<!-- #{AddressDescription} -->"),
  115. array("Code Postal:", $_POST['address']),
  116. $template);
  117. }
  118.  
  119.  
  120.  
  121. preg_match("/(<!-- #{BeginInfo} -->)(.|\n)+(<!-- #{EndInfo} -->)/", $template, $tmp, PREG_OFFSET_CAPTURE);
  122. foreach ($_POST as $key => $value) {
  123. if ($key != "counter" && $key != "email" && $key != "proprietaire" && $key != "commune" && $key != "address" && $key != "name" && $key != "situation" && $key != "phone" && $key != "chauffage" && $key != "last-name" && $key != "form-type" && $key != "g-recaptcha-response" && !empty($value)){
  124. $info = str_replace(
  125. array("<!-- #{BeginInfo} -->", "<!-- #{InfoState} -->", "<!-- #{InfoDescription} -->"),
  126. array("", ucfirst($key) . ':', $value),
  127. $tmp[0][0]);
  128.  
  129. $template = str_replace("<!-- #{EndInfo} -->", $info, $template);
  130. }
  131. }
  132.  
  133. $template = str_replace(
  134. array("<!-- #{Subject} -->", "<!-- #{SiteName} -->"),
  135. array($subject, $_SERVER['SERVER_NAME']),
  136. $template);
  137.  
  138. $mail = new PHPMailer();
  139.  
  140.  
  141. if ($formConfig['useSmtp']) {
  142. //Tell PHPMailer to use SMTP
  143. $mail->isSMTP();
  144.  
  145. //Enable SMTP debugging
  146. // 0 = off (for production use)
  147. // 1 = client messages
  148. // 2 = client and server messages
  149. $mail->SMTPDebug = 0;
  150.  
  151. $mail->Debugoutput = 'html';
  152.  
  153. // Set the hostname of the mail server
  154. $mail->Host = $formConfig['host'];
  155.  
  156. // Set the SMTP port number - likely to be 25, 465 or 587
  157. $mail->Port = $formConfig['port'];
  158.  
  159. // Whether to use SMTP authentication
  160. $mail->SMTPAuth = true;
  161. $mail->SMTPSecure = "ssl";
  162.  
  163. // Username to use for SMTP authentication
  164. $mail->Username = $formConfig['username'];
  165.  
  166. // Password to use for SMTP authentication
  167. $mail->Password = $formConfig['password'];
  168. }
  169.  
  170. $mail->From = $addresses[0][0][0];
  171.  
  172. # Attach file
  173. if (isset($_FILES['file']) &&
  174. $_FILES['file']['error'] == UPLOAD_ERR_OK) {
  175. $mail->AddAttachment($_FILES['file']['tmp_name'],
  176. $_FILES['file']['name']);
  177. }
  178.  
  179. if (isset($_POST['email'])){
  180. $mail->FromName = $_POST['email'];
  181. }else{
  182. $mail->FromName = "Site Visitor";
  183. }
  184.  
  185. foreach ($addresses[0] as $key => $value) {
  186. $mail->addAddress($value[0]);
  187. }
  188. $mail->SetFrom($_POST['email']);
  189. $mail->CharSet = 'utf-8';
  190. $mail->Subject = $subject;
  191. $mail->MsgHTML($template);
  192. $mail->send();
  193.  
  194. die('MF000');
  195. } catch (phpmailerException $e) {
  196. die('MF254');
  197. } catch (Exception $e) {
  198.  
  199. die('MF255');
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement