Your IP : 172.70.80.238


Current Path : /var/www/element/data/www/element.ru/
Upload File :
Current File : /var/www/element/data/www/element.ru/contact_popup.php

<?php

if(!$_POST) exit;


if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");



$name     = $_POST['name_popup'];
$phone   = $_POST['phone_popup'];


if(trim($name) == '') {
	echo '<div class="error_message">Attention! You must enter your name.</div>';
	exit();
} else if(trim($phone) == '') {
	echo '<div class="error_message">Введите правильный телефон.</div>';
	exit();
} else if(!is_numeric($phone)) {
	echo '<div class="error_message">Номер телефона может содержать только цифры.</div>';
	exit();
} 



// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe@yourdomain.com";

//$address = "example@themeforest.net";
$address = "go@optimism.ru";


// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."

// Example, $e_subject = '$name . ' has contacted you via Your Website.';

$e_subject = 'You\'ve been contacted by ' . $name . '.';


// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.

$e_body = "You have been contacted by: $name" . PHP_EOL . PHP_EOL;
$e_reply = "Phone: $phone" . PHP_EOL . PHP_EOL;


$msg = wordwrap( $e_body . $e_reply, 70 );

$headers = "From: element.ru" . PHP_EOL;
//$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;



////////BITRIX-24

// CRM server conection data
define('CRM_HOST', 'go.optimism.ru'); // your CRM domain name
define('CRM_PORT', '443'); // CRM server port
define('CRM_PATH', '/crm/configs/import/lead.php'); // CRM server REST service path

// CRM server authorization data
define('CRM_LOGIN', 'robot-bitrix@optimism.ru'); // login of a CRM user able to manage leads
define('CRM_PASSWORD', 'bt.Opt-15'); // password of a CRM user



// OR you can send special authorization hash which is sent by server after first successful connection with login and password
//define('CRM_AUTH', 'e54ec19f0c5f092ea11145b80f465e1a'); // authorization hash

/********************************************************************************************/
//var_dump($bx24);die;
// POST processing

	$leadData = $_POST;
//	var_dump($leadData);die;
	//var_dump($leadData['feed']); die;
	// get lead data from the form
	$postDataBx = array(
		'TITLE' => 'Заявка обратного звонка с element.ru от '.date('Y-m-d H:i'),
		'NAME' => $leadData['name_popup'],
		'PHONE_WORK' => $leadData['phone_popup'],
		'ASSIGNED_BY_ID' => 241,		
		'SOURCE_ID' => 11
	);

	// append authorization data
	if (defined('CRM_AUTH'))
	{
		$postDataBx['AUTH'] = CRM_AUTH;
	}
	else
	{
		$postDataBx['LOGIN'] = CRM_LOGIN;
		$postDataBx['PASSWORD'] = CRM_PASSWORD;
	}

	// open socket to CRM
	$fp = fsockopen("ssl://".CRM_HOST, CRM_PORT, $errno, $errstr, 30);
	if ($fp)
	{
		// prepare POST data
		$strPostData = '';
		foreach ($postDataBx as $key => $value)
			$strPostData .= ($strPostData == '' ? '' : '&').$key.'='.urlencode($value);

		//$strPostData .= "&UF_CRM_1408529282=,69";
		// prepare POST headers
		$str = "POST ".CRM_PATH." HTTP/1.0\r\n";
		$str .= "Host: ".CRM_HOST."\r\n";
		$str .= "Content-Type: application/x-www-form-urlencoded\r\n";
		$str .= "Content-Length: ".strlen($strPostData)."\r\n";
		$str .= "Connection: close\r\n\r\n";

		$str .= $strPostData;

		// send POST to CRM
		fwrite($fp, $str);

		// get CRM headers
		$result = '';
		while (!feof($fp))
		{
			$result .= fgets($fp, 128);
		}
		fclose($fp);

		// cut response headers
		$response = explode("\r\n\r\n", $result);
		$result = explode(",",$response[1]);
		$result = preg_replace("/^\'ID\'\:\'([0-9]+)\'$/",'$1',$result[1]);
//var_dump($response);die;
	//	$output = '<pre>'.print_r($response[1], 1).'</pre>';die;
		//$result = '1';
	}
	else 
	{
		echo 'Connection Failed! '.$errstr.' ('.$errno.')';
	}













///////////////


if(mail($address, $e_subject, $msg, $headers)) {

	// Email has sent successfully, echo a success page.

	echo "<fieldset>";
	echo "<div id='success_page'>";
	echo "<h1>Заявка отправлена</h1>";
	echo "<p>Cпасибо, мы свяжемся с вами.</p>";
	echo "</div>";
	echo "</fieldset>";

} else {

	echo 'ERROR!';

}