The essence of the question in the question itself: it is necessary to add a capture of UTM tags to the feedback form (Ajax) and accordingly make their transfer to the mail. I added, but for some reason they do not come to the post office. Here is my code:
HTML code
<form class="form-1" id="form-1"> <div class="border__frame"> <div class="heading">Отправьте <span>заявку на марс!</span> </div> <div class="description">И наш марсианский менеджер перезвонит вам в ближйшее время.</div> <input type="hidden" name="utm_source" value="<?php echo isset($_GET['utm_source']) ? $_GET['utm_source'] : '' ;?>"> <input type="hidden" name="utm_medium" value="<?php echo isset($_GET['utm_medium']) ? $_GET['utm_medium'] : '' ;?>"> <input type="hidden" name="utm_campaign" value="<?php echo isset($_GET['utm_campaign']) ? $_GET['utm_campaign'] : '' ;?>"> <input type="hidden" name="utm_term" value="<?php echo isset($_GET['utm_term']) ? $_GET['utm_term'] : '' ;?>"> <input type="hidden" name="utm_content" value="<?php echo isset($_GET['utm_content']) ? $_GET['utm_content'] : '' ;?>"> <input type="hidden" name="formid" value="с первого экрана Pop-up"> <input type="text" name="name" placeholder="Ваше имя" required> <input class="index__phone" name="code" type="tel" maxlength="3" placeholder="123" required> <input class="number__phone" name="tel" type="tel" placeholder="325-54-94" required> <button class="btn-submit-mars" type="submit">Отправить заявку на марс</button> </div> </form> PHP handler
$recepient = "xxx@gmail.com"; $sitename = "Марсоход"; $formid = trim($_POST["formid"]); $utm_source = trim($_POST["utm_source"]); $utm_medium = trim($_POST["utm_medium"]); $utm_campaign = trim($_POST["utm_campaign"]); $utm_term = trim($_POST["utm_term"]); $utm_content = trim($_POST["utm_content"]); $name = trim($_POST["name"]); $code = trim($_POST["code"]); $tel = trim($_POST["tel"]); $message = trim($_POST["message"]); $message = "форма $formid \nИсточник перехода: $utm_source $utm_medium $utm_campaign $utm_term $utm_content \nИмя: $name \nТелефон: $code $tel \nВопрос: $message"; $pagetitle = "Новое сообщение с сайта \"$sitename\""; mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset=\"utf-8\"\n From: $recepient"); js
$("#form-1").validate({ rules: { name: { required: true, minlength: 2 }, code: { required: true, digits: true, minlength: 3, maxlength: 3 }, tel: { required: true, minlength: 7, maxlength: 9 } }, messages: { name: { required: "Неверно заполнено поле :(", minlength: "Минимальное кол-во символов 2" }, code: { required: "Введите код", digits: "Обязательно цифры", minlength: "3 символа" }, tel: { required: "Введите номер телефона :(", minlength: "Необходимо 7 символов" } } }); $("#form-1").submit(function() { if ($("#form-1").valid()) { var th = $(this); $.ajax({ type: "POST", url: "mail.php", data: th.serialize() }).done(function() { $(".success").addClass("visible"); setTimeout(function() { // Done Functions th.trigger("reset"); $(".success").removeClass("visible"); }, 1000); $('#form-1')[0].reset( setTimeout(function() {}, 1000) ); $("#form-1").hide(); $('.mfp-bg.mfp-ready').css({ 'display': 'none' }); $('#popUpMessage').removeClass('hiddenDiv'); setTimeout(function() { $('#popUpMessage').addClass('hiddenDiv'); }, 5000); }); } return false; }); In principle, nothing seems to be complicated, but it does not work. A letter comes to the form: and wherever it is. Source: .... Keyword: .... the form itself is working and tested more than once. Tell or show how to correctly set these tags in the form, to be honest, google rummaged, used examples - but there’s no use. Thank.