Собственный скрипт записи писем в webform


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. if($_GET[er]){
  3. if($_SESSION[num_order]>2){$_SESSION[two]='<h2 id="er">Вы уже отправили 2 заявки</h2>';}
  4. if($_SESSION[error]){ echo iconv("UTF-8", "cp1251", $_SESSION[error]);}
  5. elseif($_SESSION[two]){echo iconv("UTF-8", "cp1251", $_SESSION[two]);}
  6. elseif($_SESSION[ok]){echo iconv("UTF-8", "cp1251", $_SESSION[ok]); exit();}
  7. exit();
  8. }
  9. if($_POST && $_SESSION[num_order]<3){
  10. if(!preg_match('#[-a-zA-Z0-9\.]+@[-a-zA-Z0-9]+\.[a-zA-Z]+#',$_POST[email])){$_SESSION[error]='<h2 id="er">Не правильно указан E-mail</h2>';exit();}
  11. if(strcasecmp($_POST[email],'[email protected]')==0){$_SESSION[error]='<h2 id="er">Не правильно указан E-mail</h2>';exit();}
  12. if($_POST[seo])$work_ar[]='seo';
  13. if($_POST[create])$work_ar[]='create';
  14. if($_POST[support])$work_ar[]='support';
  15. print_r($work_ar);
  16. if(!is_array($work_ar)){$_SESSION[error]='<h2 id="er">Укажите работы.</h2>';exit();}
  17.  
  18. $bdlink=mysql_connect('host.ru','user','pass');
  19. mysql_select_db('bd_name',$bdlink);
  20.  
  21. mysql_query("INSERT INTO `webform_submissions`(nid,uid,submitted,remote_addr) VALUE('3','0','".time()."','{$_SERVER['REMOTE_ADDR']}')",$bdlink);
  22. $max_sid=mysql_fetch_array(mysql_query("SELECT MAX(sid) FROM webform_submissions"));$max_sid=$max_sid[0];
  23.  
  24. mysql_query("INSERT INTO `webform_submitted_data`(nid,sid,cid,no,data) VALUE('3','$max_sid','1','0','{$_POST[email]}')",$bdlink);
  25. mysql_query("INSERT INTO `webform_submitted_data`(nid,sid,cid,no,data) VALUE('3','$max_sid','2','0','{$_POST[phone]}')",$bdlink);
  26. mysql_query("INSERT INTO `webform_submitted_data`(nid,sid,cid,no,data) VALUE('3','$max_sid','3','0','".iconv('UTF-8', 'cp1251', $_POST[name])."')",$bdlink);
  27. mysql_query("INSERT INTO `webform_submitted_data`(nid,sid,cid,no,data) VALUE('3','$max_sid','4','0','{$_POST[sitename]}')",$bdlink);
  28.  
  29. $c=0;
  30. if($work_ar[0]){mysql_query("INSERT INTO `webform_submitted_data`(nid,sid,cid,no,data) VALUE('3','$max_sid','5','$c','{$work_ar[0]}')",$bdlink);
  31. $c++;}
  32. if($work_ar[1]){mysql_query("INSERT INTO `webform_submitted_data`(nid,sid,cid,no,data) VALUE('3','$max_sid','5','$c','{$work_ar[1]}')",$bdlink);
  33. $c++;}
  34. if($work_ar[2]){mysql_query("INSERT INTO `webform_submitted_data`(nid,sid,cid,no,data) VALUE('3','$max_sid','5','$c','{$work_ar[2]}')",$bdlink);
  35. $c++;}
  36. mysql_close($bdlink);
  37. foreach($_POST as $key => $line){$mes.=($line)?"$key: $line <br>
  38. ":'';}
  39.  
  40. $headers = "Content-type: text/html; charset=utf-8
  41. ";
  42. $headers .= "From: www <[email protected]>
  43. ";
  44. $headers .= "Bcc: [email protected]
  45. ";
  46. mail('[email protected]','Заказ с сайта',$mes,$headers);
  47. $_SESSION[ok]='<h2>Ваша заявка принята. Стартуем!</h2>';
  48. $_SESSION[error]='';
  49. $_SESSION[num_order]=($_SESSION[num_order])?$_SESSION[num_order]+1:1;
  50. }
  51. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.