← Back
Editing: contact.php
<?php /** * Template Name: Contact form */ function send($method,$datas=[], $bot_token){ $url = "https://api.telegram.org/bot".$bot_token."/".$method; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_POSTFIELDS,$datas); $res = curl_exec($ch); if(curl_error($ch)){ var_dump(curl_error($ch)); }else{ return json_decode($res); } } function reCaptcha($recaptcha){ $secret = "6Lcwi_QpAAAAAHLFEquYHv_flkwDTuKrFgDxbum2"; $ip = $_SERVER['REMOTE_ADDR']; $postvars = array("secret"=>$secret, "response"=>$recaptcha, "remoteip"=>$ip); $url = "https://www.google.com/recaptcha/api/siteverify"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars); $data = curl_exec($ch); curl_close($ch); return json_decode($data, true); } if ($_SERVER["REQUEST_METHOD"] == "POST") { get_header(); // Retrieve form data $first_name = $_POST["firstname"]; $last_name = $_POST["lastname"]; $phone_number = $_POST["phone"]; $brand = $_POST["brand"]; $message = $_POST["your-message"]; $email_content = "#$brand\n"; $email_content .= "🟢Имя: $first_name\n"; $email_content .= "🟢Фамилия: $last_name\n"; $email_content .= "☎️Телефон: $phone_number\n"; $email_content .= "💬Сообщение: $message\n"; $bot_token = "7329474622:AAEEkv9phbsUeKX3qc0SGp1-L2GbrTMgETM"; $chat_id = '-1002227271425'; if (empty($errMsg)){ if(!isset($_POST['g-recaptcha-response']) || empty($_POST['g-recaptcha-response'])) { echo 'reCAPTCHA verification failed, please try again.'; } else { $secret = '6Lcwi_QpAAAAAIX1KwlWRpWpNAJ5kzj19HSl_-AK'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $response = json_decode($response); if ($response->success) { $sendToTelegram = send('sendMessage', ['chat_id' => $chat_id, 'text' => $email_content, 'parse_mode' => "markdown"], $bot_token); // Send the email. if ($sendToTelegram) { // Set a 200 (okay) response code. http_response_code(200); ?> <div class="container p-5"> <div class="py-4" style="background: gainsboro;"> <p class="m-5"><?= L::thank_you?></p> </div> </div> <?php } } } } else { // Set a 500 (internal server error) response code. http_response_code(500); echo $errMsg; } } else{ wp_redirect(home_url()); exit(); } get_footer(); ?>
Save File
Cancel