Return to Snippet

Revision: 35072
at November 2, 2010 02:51 by nuwak


Initial Code
<?php
session_start();
if($_GET[er]){
if($_SESSION[num_order]>2){$_SESSION[two]='<h2 id="er">Вы уже отправили 2 заявки</h2>';}
if($_SESSION[error]){ echo iconv("UTF-8", "cp1251", $_SESSION[error]);}
elseif($_SESSION[two]){echo iconv("UTF-8", "cp1251", $_SESSION[two]);}
elseif($_SESSION[ok]){echo iconv("UTF-8", "cp1251", $_SESSION[ok]); exit();}
exit();
}
if($_POST && $_SESSION[num_order]<3){
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();}
if(strcasecmp($_POST[email],'[email protected]')==0){$_SESSION[error]='<h2 id="er">Не правильно указан E-mail</h2>';exit();}
if($_POST[seo])$work_ar[]='seo';
if($_POST[create])$work_ar[]='create';
if($_POST[support])$work_ar[]='support';
print_r($work_ar);
if(!is_array($work_ar)){$_SESSION[error]='<h2 id="er">Укажите работы.</h2>';exit();}

 $bdlink=mysql_connect('host.ru','user','pass');
 mysql_select_db('bd_name',$bdlink);

 mysql_query("INSERT INTO `webform_submissions`(nid,uid,submitted,remote_addr) VALUE('3','0','".time()."','{$_SERVER['REMOTE_ADDR']}')",$bdlink);
$max_sid=mysql_fetch_array(mysql_query("SELECT MAX(sid) FROM webform_submissions"));$max_sid=$max_sid[0];

mysql_query("INSERT INTO `webform_submitted_data`(nid,sid,cid,no,data) VALUE('3','$max_sid','1','0','{$_POST[email]}')",$bdlink);
mysql_query("INSERT INTO `webform_submitted_data`(nid,sid,cid,no,data) VALUE('3','$max_sid','2','0','{$_POST[phone]}')",$bdlink);
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);
mysql_query("INSERT INTO `webform_submitted_data`(nid,sid,cid,no,data) VALUE('3','$max_sid','4','0','{$_POST[sitename]}')",$bdlink);

$c=0;
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);
$c++;}
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);
$c++;}
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);
$c++;}
 mysql_close($bdlink);
 foreach($_POST as $key => $line){$mes.=($line)?"$key: $line <br>
":'';}

 $headers  = "Content-type: text/html; charset=utf-8 
";
$headers .= "From: www <[email protected]>
";
$headers .= "Bcc: [email protected]
";
mail('[email protected]','Заказ с сайта',$mes,$headers);
 $_SESSION[ok]='<h2>Ваша заявка принята. Стартуем!</h2>';
 $_SESSION[error]='';
 $_SESSION[num_order]=($_SESSION[num_order])?$_SESSION[num_order]+1:1;
 }
?>

Initial URL

                                

Initial Description

                                

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

Initial Tags
mail, drupal

Initial Language
PHP