如何修改表格?

时间:2019-04-01 19:10:51

标签: javascript php ajax

伙计们。问题我没有从站点表单收到消息。尝试过不同的邮件。那里没有错误...

我检查了主机以阻止消息,但是一切正常。即使是垃圾邮件也不会发送邮件。我使用了临时邮件,但什么也没收到。试图清理缓存,进行更新-没有帮助

我尝试使用phpmailer,但结果相同。

也许您有任何想法吗?

查询代码。我使用Ajax

$('#form').submit(function() {
    var th = $(this);
    $.ajax({
      type: 'POST',

      url: '/mail/contact-form.php', // this file return 200
      data: th.serialize()
    }).done(function() {
      $('.hooray').css('display', 'flex');

      setTimeout(function() {
        $('.hooray').css('display', 'none');
        th.trigger('reset');
        $('input').val('');
      }, 2000);
    });
    return false;
  });
form#form(method='POST')
            h5 Просто заполните форму и наш менеджер свяжестся с вами.
// I use hidden fields
            input(type="hidden" name="project_name" value="Site Name")
            input(type="hidden" name="admin_email" value="menu85@yandex.ru")
            input(type="hidden" name="form_subject" value="Form Subject")
            .form-group
                label Ваше Имя
                input(type="text" name='user_name' data-validation-length="min4" data-validation-error-msg="Имя должно быть больше 4 символов")
            .form-group
                label Ваш E-mail
                input(type="email" email='user_email' data-validation="email" data-validation-error-msg="Введитguе корректный E-mail")
            .form-group
                label Ваш Телефон
                input(type="number" phone='user_phone' data-validation="number" data-validation-error-msg="Введите корректный номер")

            button(type="submit").btn Отправить заявку
<?php
$method = $_SERVER['REQUEST_METHOD'];
//Script Foreach
$c = true;
if ( $method === 'POST' ) {
    $project_name = trim($_POST["project_name"]);
    $admin_email  = trim($_POST["admin_email"]);
    $form_subject = trim($_POST["form_subject"]);
    foreach ( $_POST as $key => $value ) {
        if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
            $message .= "
            " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
                <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
                <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
            </tr>
            ";
        }
    }
} else if ( $method === 'GET' ) {
    $project_name = trim($_GET["project_name"]);
    $admin_email  = trim($_GET["admin_email"]);
    $form_subject = trim($_GET["form_subject"]);
    foreach ( $_GET as $key => $value ) {
        if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
            $message .= "
            " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
                <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
                <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
            </tr>
            ";
        }
    }
}
$message = "<table style='width: 100%;'>$message</table>";
function adopt($text) {
    return '=?UTF-8?B?'.Base64_encode($text).'?=';
}
$headers = "MIME-Version: 1.0" . PHP_EOL .
"Content-Type: text/html; charset=utf-8" . PHP_EOL .
'From: '.adopt($project_name).' <'.$admin_email.'>' . PHP_EOL .
'Reply-To: '.$admin_email.'' . PHP_EOL;
mail($admin_email, adopt($form_subject), $message, $headers );

0 个答案:

没有答案