Advertisement
Guest User

Форма

a guest
Feb 14th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.39 KB | None | 0 0
  1. <?php
  2.  
  3. function ValidateEmail($email)
  4.  
  5. {
  6.  
  7. $pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
  8.  
  9. return preg_match($pattern, $email);
  10.  
  11. }
  12.  
  13. if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['formid'] == 'form_zakazform1')
  14.  
  15. {
  16.  
  17. $mailto = 'appolonov.leonid@mail.ru';
  18.  
  19. $mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
  20.  
  21. $subject = 'Заявка!';
  22.  
  23. $message = 'Данные:';
  24.  
  25. $success_url = './good.html';
  26.  
  27. $error_url = '';
  28.  
  29. $csvFile = "./formdata.csv";
  30.  
  31. $error = '';
  32.  
  33. $autoresponder_from = 'appolonov.leonid@mail.ru';
  34.  
  35. $autoresponder_subject = 'Заказ на сайте!';
  36.  
  37. $autoresponder_message = 'Здравствуйте!
  38.  
  39. Вы оставили заявку!';
  40.  
  41. $eol = "\n";
  42.  
  43. $max_filesize = isset($_POST['filesize']) ? $_POST['filesize'] * 1024 : 1024000;
  44.  
  45. $boundary = md5(uniqid(time()));
  46.  
  47. $header = 'From: '.$mailfrom.$eol;
  48.  
  49. $header .= 'Reply-To: '.$mailfrom.$eol;
  50.  
  51. $header .= 'MIME-Version: 1.0'.$eol;
  52.  
  53. $header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;
  54.  
  55. $header .= 'X-Mailer: PHP v'.phpversion().$eol;
  56.  
  57. if (!ValidateEmail($mailfrom))
  58.  
  59. {
  60.  
  61. $error .= "The specified email address is invalid!\n<br>";
  62.  
  63. }
  64.  
  65. if (!empty($error))
  66.  
  67. {
  68.  
  69. $errorcode = file_get_contents($error_url);
  70.  
  71. $replace = "##error##";
  72.  
  73. $errorcode = str_replace($replace, $error, $errorcode);
  74.  
  75. echo $errorcode;
  76.  
  77. exit;
  78.  
  79. }
  80.  
  81. $internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response");
  82.  
  83. $message .= $eol;
  84.  
  85. foreach ($_POST as $key => $value)
  86.  
  87. {
  88.  
  89. if (!in_array(strtolower($key), $internalfields))
  90.  
  91. {
  92.  
  93. $logdata .= ',';
  94.  
  95. if (!is_array($value))
  96.  
  97. {
  98.  
  99. $message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;
  100.  
  101. $value = str_replace(",", " ", $value);
  102.  
  103. $logdata .= $value;
  104.  
  105. }
  106.  
  107. else
  108.  
  109. {
  110.  
  111. $message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;
  112.  
  113. $logdata .= implode("|", $value);
  114.  
  115. }
  116.  
  117. }
  118.  
  119. }
  120.  
  121. $logdata = str_replace("\r", "", $logdata);
  122.  
  123. $logdata = str_replace("\n", " ", $logdata);
  124.  
  125. $logdata .= "\r\n";
  126.  
  127. $handle = fopen($csvFile, 'a') or die("can't open file");
  128.  
  129. $logtime = date("Y-m-d H:i:s,");
  130.  
  131. fwrite($handle, $logtime);
  132.  
  133. fwrite($handle, $logdata);
  134.  
  135. fclose($handle);
  136.  
  137. $body = 'This is a multi-part message in MIME format.'.$eol.$eol;
  138.  
  139. $body .= '--'.$boundary.$eol;
  140.  
  141. $body .= 'Content-Type: text/plain; charset=UTF-8'.$eol;
  142.  
  143. $body .= 'Content-Transfer-Encoding: 8bit'.$eol;
  144.  
  145. $body .= $eol.stripslashes($message).$eol;
  146.  
  147. if (!empty($_FILES))
  148.  
  149. {
  150.  
  151. foreach ($_FILES as $key => $value)
  152.  
  153. {
  154.  
  155. if ($_FILES[$key]['error'] == 0 && $_FILES[$key]['size'] <= $max_filesize)
  156.  
  157. {
  158.  
  159. $body .= '--'.$boundary.$eol;
  160.  
  161. $body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;
  162.  
  163. $body .= 'Content-Transfer-Encoding: base64'.$eol;
  164.  
  165. $body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;
  166.  
  167. $body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;
  168.  
  169. }
  170.  
  171. }
  172.  
  173. }
  174.  
  175. $body .= '--'.$boundary.'--'.$eol;
  176.  
  177. if ($mailto != '')
  178.  
  179. {
  180.  
  181. mail($mailto, $subject, $body, $header);
  182.  
  183. }
  184.  
  185. $autoresponder_header = 'From: '.$autoresponder_from.$eol;
  186.  
  187. $autoresponder_header .= 'Reply-To: '.$autoresponder_from.$eol;
  188.  
  189. $autoresponder_header .= 'MIME-Version: 1.0'.$eol;
  190.  
  191. $autoresponder_header .= 'Content-Type: text/plain; charset=UTF-8'.$eol;
  192.  
  193. $autoresponder_header .= 'Content-Transfer-Encoding: 8bit'.$eol;
  194.  
  195. $autoresponder_header .= 'X-Mailer: PHP v'.phpversion().$eol;
  196.  
  197. mail($mailfrom, $autoresponder_subject, $autoresponder_message, $autoresponder_header);
  198.  
  199. header('Location: '.$success_url);
  200.  
  201. exit;
  202.  
  203. }
  204.  
  205. ?>
  206.  
  207. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  208.  
  209. <html>
  210.  
  211. <head>
  212.  
  213. <link href="http://fonts.googleapis.com/css?family=PT+Sans&subset=cyrillic,cyrillic-ext" rel="stylesheet" type="text/css">
  214.  
  215. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  216.  
  217. <title>Безымянная страница</title>
  218.  
  219. <meta name="robots" content="NOINDEX, NOFOLLOW">
  220.  
  221. <link href="style/7.css" rel="stylesheet" type="text/css">
  222.  
  223. <link href="style/form_zakaz.css" rel="stylesheet" type="text/css">
  224.  
  225. <script type="text/javascript">
  226.  
  227. function ValidateZakaz_keys(theForm)
  228.  
  229. {
  230.  
  231. var regexp;
  232.  
  233. if (theForm.form_zakazEditbox1.value == "")
  234.  
  235. {
  236.  
  237. alert("Введите Ваше имя");
  238.  
  239. theForm.form_zakazEditbox1.focus();
  240.  
  241. return false;
  242.  
  243. }
  244.  
  245. if (theForm.form_zakazEditbox1.value.length < 1)
  246.  
  247. {
  248.  
  249. alert("Введите Ваше имя");
  250.  
  251. theForm.form_zakazEditbox1.focus();
  252.  
  253. return false;
  254.  
  255. }
  256.  
  257. regexp = /^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i;
  258.  
  259. if (!regexp.test(theForm.form_zakazEditbox2.value))
  260.  
  261. {
  262.  
  263. alert("Please enter a valid email address.");
  264.  
  265. theForm.form_zakazEditbox2.focus();
  266.  
  267. return false;
  268.  
  269. }
  270.  
  271. if (theForm.form_zakazEditbox2.value == "")
  272.  
  273. {
  274.  
  275. alert("Please enter a value for the \"email\" field.");
  276.  
  277. theForm.form_zakazEditbox2.focus();
  278.  
  279. return false;
  280.  
  281. }
  282.  
  283. if (theForm.form_zakazEditbox2.value.length < 1)
  284.  
  285. {
  286.  
  287. alert("Please enter at least 1 characters in the \"email\" field.");
  288.  
  289. theForm.form_zakazEditbox2.focus();
  290.  
  291. return false;
  292.  
  293. }
  294.  
  295. return true;
  296.  
  297. }
  298.  
  299. </script>
  300.  
  301. <script type="text/javascript" src="js/wwb10.min.js"></script>
  302.  
  303. <script>
  304.  
  305. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  306.  
  307. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  308.  
  309. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  310.  
  311. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  312.  
  313.  
  314.  
  315. ga('create', 'UA-57964998-1', 'auto');
  316.  
  317. ga('send', 'pageview');
  318.  
  319.  
  320.  
  321. </script>
  322.  
  323. </head>
  324.  
  325. <body>
  326.  
  327. <div id="wb_form_zakazForm1" style="position:absolute;left:0px;top:0px;width:354px;height:234px;z-index:7;">
  328.  
  329. <form name="Zakaz_keys" method="post" action="<?php echo basename(__FILE__); ?>" enctype="multipart/form-data" accept-charset="UTF-8" target="_blank" id="form_zakazForm1" onsubmit="return ValidateZakaz_keys(this)">
  330.  
  331. <input type="hidden" name="formid" value="form_zakazform1">
  332.  
  333. <div id="wb_form_zakazImage2" style="position:absolute;left:17px;top:153px;width:320px;height:51px;z-index:0;">
  334.  
  335. <img src="images/button2.png" id="form_zakazImage2" alt=""></div>
  336.  
  337. <input type="text" id="form_zakazEditbox1" style="position:absolute;left:20px;top:44px;width:264px;height:43px;line-height:43px;z-index:1;" name="Имя:" value="" placeholder="&#1042;&#1074;&#1077;&#1076;&#1080;&#1090;&#1077; &#1042;&#1072;&#1096;&#1077; &#1080;&#1084;&#1103;:">
  338.  
  339. <input type="text" id="form_zakazEditbox2" style="position:absolute;left:20px;top:93px;width:264px;height:43px;line-height:43px;z-index:2;" name="email" value="" placeholder="&#1042;&#1074;&#1077;&#1076;&#1080;&#1090;&#1077; &#1042;&#1072;&#1096; email:">
  340.  
  341. <div id="wb_form_zakazImage1" style="position:absolute;left:17px;top:153px;width:320px;height:51px;z-index:3;">
  342.  
  343. <img src="images/button.png" id="form_zakazImage1" alt=""></div>
  344.  
  345. <div id="wb_form_zakazText1" style="position:absolute;left:103px;top:206px;width:153px;height:14px;z-index:4;text-align:left;">
  346.  
  347. <span style="color:#000000;font-family:'PT Sans';font-size:11px;">Ваши данные в безопасности!</span></div>
  348.  
  349. <div id="wb_form_zakazText2" style="position:absolute;left:104px;top:9px;width:178px;height:24px;z-index:5;text-align:left;">
  350.  
  351. <span style="color:#000000;font-family:'PT Sans';font-size:19px;"><strong>Заполните форму!</strong></span></div>
  352.  
  353. <input type="submit" id="form_zakazButton1" onmouseover="ShowObject('wb_form_zakazImage1', 0);return false;" onmouseout="ShowObject('wb_form_zakazImage1', 1);return false;" name="" value="" style="position:absolute;left:17px;top:153px;width:319px;height:51px;z-index:6;">
  354.  
  355. </form>
  356.  
  357. </div>
  358.  
  359. <!-- Yandex.Metrika counter -->
  360.  
  361. <script type="text/javascript">
  362.  
  363. (function (d, w, c) {
  364.  
  365. (w[c] = w[c] || []).push(function() {
  366.  
  367. try {
  368.  
  369. w.yaCounter27398030 = new Ya.Metrika({id:27398030,
  370.  
  371. webvisor:true,
  372.  
  373. clickmap:true,
  374.  
  375. trackLinks:true,
  376.  
  377. accurateTrackBounce:true});
  378.  
  379. } catch(e) { }
  380.  
  381. });
  382.  
  383.  
  384.  
  385. var n = d.getElementsByTagName("script")[0],
  386.  
  387. s = d.createElement("script"),
  388.  
  389. f = function () { n.parentNode.insertBefore(s, n); };
  390.  
  391. s.type = "text/javascript";
  392.  
  393. s.async = true;
  394.  
  395. s.src = (d.location.protocol == "https:" ? "https:" : "http:") + "//mc.yandex.ru/metrika/watch.js";
  396.  
  397.  
  398.  
  399. if (w.opera == "[object Opera]") {
  400.  
  401. d.addEventListener("DOMContentLoaded", f, false);
  402.  
  403. } else { f(); }
  404.  
  405. })(document, window, "yandex_metrika_callbacks");
  406.  
  407. </script>
  408.  
  409. <noscript><div><img src="//mc.yandex.ru/watch/27398030" style="position:absolute; left:-9999px;" alt=""/></div></noscript>
  410.  
  411. <!-- /Yandex.Metrika counter -->
  412.  
  413. <!-- BEGIN JIVOSITE CODE {literal} -->
  414. <script type="text/javascript"> (function(){ var widget_id = 'qKn7yhGcVc';
  415. var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = '//code.jivosite.com/script/widget/'+widget_id; var ss = document.getElementsByTagName('script')[0]; ss.parentNode.insertBefore(s, ss);})();
  416. </script>
  417. <!-- {/literal} END JIVOSITE CODE --></body>
  418.  
  419. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement