Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('form.contact-form .form-submit').on('click', function(event){
- console.log('Modal sent ot Admin');
- event.preventDefault();
- event.stopImmediatePropagation();
- if (!event.isDefaultPrevented()) {
- event.returnValue = false;
- }
- let form = $(this).closest('form.contact-form');
- form.find('.modal__reject').fadeOut();
- form.find('.modal__resolve').fadeOut();
- form.find('.error').removeClass('.error');
- var formError = false;
- form.find('input').each(function (){
- if($(this).val() == ''){
- $(this).addClass('error');
- $(this).select();
- formError = true;
- return false;
- }
- });
- if (!formError) {
- let name = form.find('input[name="name"]').val();
- let phone = form.find('input[name="phone"').val();
- let formData = new FormData();
- formData.append('name', name);
- formData.append('phone', phone);
- $.ajax({
- url: '/message.php',
- type: 'POST',
- dataType: 'json',
- cache: false,
- contentType: false,
- processData: false,
- data: formData,
- beforeSend: function () {
- form.siblings('.formLoader').fadeIn();
- let formheight = form.height();
- form.height(formheight);
- form.find('.modal__contact-form').fadeOut();
- },
- error: function (er) {
- form.siblings('.formLoader').fadeOut();
- form.find('.modal__resolve').fadeOut();
- form.find('.modal__reject').fadeIn();
- form.find('.form-submit-contact').text("Не отправлено. Попробовать еще раз?");
- form.find('div.data-error').fadeIn();
- console.log(er);
- },
- success: function(){
- form.find('.form-submit-contact').text("Успешно!").removeClass('.form-submit');
- form.find('div.data-error').fadeOut();
- setTimeout(function (){
- form.siblings('.formLoader').fadeOut();
- form.find('.modal__reject').fadeOut();
- form.find('.modal__resolve').fadeIn();
- form.find('input[name="name"]').val('');
- form.find('input[name="phone"]').val('');
- },1500);
- },
- complete: function () {
- }
- });
- }
- // return false;
- });
- $('form.service-form .form-submit').on('click', function(event){
- console.log('Form sent to Admin');
- event.preventDefault();
- event.stopImmediatePropagation();
- if (!event.isDefaultPrevented()) {
- event.returnValue = false;
- }
- let form = $(this).closest('form.service-form');
- form.find('.modal__reject').fadeOut();
- form.find('.modal__resolve').fadeOut();
- form.find('.error').removeClass('.error');
- var formError = false;
- form.find('input').each(function (){
- if($(this).val() == '' && $(this).attr('id') != "file"){
- $(this).addClass('error');
- $(this).select();
- formError = true;
- return false;
- }
- });
- if (!formError) {
- let name = form.find('input[name="name"]').val();
- let phone = form.find('input[name="phone"').val();
- let square = form.find('input[name="square"]').val();
- let address = form.find('input[name="address"').val();
- let task = $('textarea[name="description"]').val();
- let formData = new FormData();
- formData.append('service', $('.service__name').text());
- formData.append('name', name);
- formData.append('phone', phone);
- formData.append('square', square);
- formData.append('address', address);
- formData.append('task', task);
- $.each($('#file')[0].files, function(i, file) {
- formData.append('file', file);
- });
- $.ajax({
- url: '/project-request.php',
- type: 'POST',
- dataType: 'json',
- cache: false,
- contentType: false,
- processData: false,
- data: formData,
- beforeSend: function () {
- form.siblings('.formLoader').fadeIn();
- let formheight = form.height();
- form.height(formheight);
- form.find('.modal__service-form').fadeOut();
- form.find('.modal__reject').fadeOut();
- form.find('.modal__resolve').fadeOut();
- },
- error: function (er) {
- form.siblings('.formLoader').fadeOut();
- form.find('.modal__resolve').fadeOut();
- form.find('.modal__reject').fadeIn();
- form.find('div.data-error').fadeIn();
- console.log(er);
- },
- success: function(){
- form.find('div.data-error').fadeOut();
- setTimeout(function (){
- form.siblings('.formLoader').fadeOut();
- form.find('.modal__reject').fadeOut();
- form.find('.modal__resolve').fadeIn();
- form.find('input').val('');
- },1500);
- },
- complete: function () {
- }
- });
- }
- // return false;
- });
- /////////////////////////////////////////PHP////////////////////////////////////////
- <?php
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- //Load Composer's autoloader
- require 'vendor/autoload.php';
- //Instantiation and passing `true` enables exceptions
- $mail = new PHPMailer(true);
- if(isset($_SERVER["HTTP_CF_CONNECTING_IP"])) { // http ip user
- $user_ip = $_SERVER["HTTP_CF_CONNECTING_IP"];
- } else {
- $user_ip = $_SERVER["REMOTE_ADDR"];
- }
- $ch = curl_init('http://ip-api.com/json/' . $user_ip . '?lang=ru'); // get place
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_HEADER, false);
- $res = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($res, true);
- $country = $res['country'];
- $city = $res['city'];
- $place = $res['country'] . ', ' . $res['city']; // string user place
- $arr = array(
- 'IP :' => $user_ip,
- 'Откуда: ' => $place,
- 'Имя: ' => $_POST['name'],
- 'Телефон: ' => $_POST['phone']
- );
- $tgtxt = 'Новая заявка! %0A';
- $mailtxt = '<h1>Новая заявка!</h1>';
- foreach ($arr as $key => $value)
- {
- $tgtxt .= "<b>" . $key . "</b> " . $value . "%0A";
- $mailtxt .= "<p> <b>" . $key . "</b> " . $value . "</p>";
- };
- //echo $mailtxt;
- // tg code
- $token = "1411837202:AAHfOxhPCbA-1At9Lng8R7fH5T0Ld3zYWmw";
- $chat_id = "-1001478897928";
- $url = "https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$tgtxt}";
- $ch = curl_init();
- curl_setopt( $ch, CURLOPT_URL, $url );
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
- curl_setopt( $ch, CURLOPT_POST, 1 );
- curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208' );
- $curl_scraped_page = curl_exec( $ch );
- curl_close( $ch );
- // tg code end
- // mail code
- try
- {
- //Server settings
- //Recipients
- $mail->setFrom('green-mail@greenstone-team.ru', 'Green-mail');
- $mail->addAddress('kirya.shkolnik@theweather.space'); //Name is optional
- //Content
- $mail->isHTML(true); //Set email format to HTML
- $mail->Subject = 'Заявка с сайта Green Stone';
- $mail->Body = $mailtxt;
- $mail->AltBody = $mailtxt;
- $mail->send();
- echo 'true';
- }
- catch(Exception $e)
- {
- echo "false";
- }
- // mail code end
- echo "true";
Add Comment
Please, Sign In to add comment