E
E
Eugene2018-02-15 09:12:43
PHP
Eugene, 2018-02-15 09:12:43

Why are krakozyabry sent?

The point is. One-pager. Below is a bootstrap form with a js handler

Handler
$('#contact-submit').click(function (e) {
      e.preventDefault();
      var error = false;
      var name = $('#name').val();
      var email = $('#email').val();
      var subject = $('#subject').val();
      var message = $('#message').val();
      if (name.length == 0) {
        var error = true;
        $('#name').css("border-color", "#D8000C");
      } else {
        $('#name').css("border-color", "#666");
      }
      if (email.length == 0 || email.indexOf('@') == '-1') {
        var error = true;
        $('#email').css("border-color", "#D8000C");
      } else {
        $('#email').css("border-color", "#666");
      }
      if (subject.length == 0) {
        var error = true;
        $('#subject').css("border-color", "#D8000C");
      } else {
        $('#subject').css("border-color", "#666");
      }
      if (message.length == 0) {
        var error = true;
        $('#message').css("border-color", "#D8000C");
      } else {
        $('#message').css("border-color", "#666");
      }
      if (error == false) {
        $('#contact-submit').attr({
          'disabled': 'false',
          'value': 'Sending...'
        });
        $.post("sendmail.php", $("#contact-form").serialize(), function (result) {

          if (result == 'sent') {
            $('#cf-submit').remove();
            $('#mail-success').fadeIn(500);
          } else {
            $('#mail-fail').fadeIn(500);
            $('#contact-submit').removeAttr('disabled').attr('value', 'Send The Message');
          }
        });
      }
    });


Here is the form itself, which is in index.html
The form
<div class="contact-form col-md-6 wow fadeInUp" data-wow-duration="500ms" data-wow-delay="300ms">
            <form id="contact-form" method="post" action="sendmail.php" role="form">
            
              <div class="form-group">
                <input type="text" placeholder="Ваше имя" class="form-control" name="name" id="name">
              </div>
              
              <div class="form-group">
                <input type="email" placeholder="Ваша почта" class="form-control" name="email" id="email">
              </div>
              
              <div class="form-group">
                <input type="text" placeholder="Номер телефона" class="form-control" name="subject" id="subject">
              </div>
              
              <div class="form-group">
                <textarea rows="6" placeholder="Сообщение" class="form-control" name="message" id="message"></textarea>	
              </div>
              
              <div id="mail-success" class="success">
                Отправлено, мы свяжемся с вами в ближайшее время
              </div>
              
              <div id="mail-fail" class="error">
                Извините, но вы допустили где-то ошибку
              </div>
              
              <div id="cf-submit">
                <input type="submit" id="contact-submit" class="btn btn-transparent" value="Отправить">
              </div>						
              
            </form>

Well, the php file sendmail.php
php
<?php

$errorMSG = "";

// NAME
if (empty($_POST["name"])) {
    $errorMSG = "Name is required ";
} else {
    $name = $_POST["name"];
}

// EMAIL
if (empty($_POST["email"])) {
    $errorMSG .= "Email is required ";
} else {
    $email = $_POST["email"];
}

// MSG SUBJECT
if (empty($_POST["subject"])) {
    $errorMSG .= "Subject is required ";
} else {
    $msg_subject = $_POST["subject"];
}


// MESSAGE
if (empty($_POST["message"])) {
    $errorMSG .= "Message is required ";
} else {
    $message = $_POST["message"];
}


$EmailTo = "[email protected]";
$Subject = "New Message Received";

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= $msg_subject;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From:".$email);

// redirect to success page
if ($success && $errorMSG == ""){
   echo "success";
}else{
    if($errorMSG == ""){
        echo "Something went wrong :(";
    } else {
        echo $errorMSG;
    }
}

?>

In fact, it seems like a banal simple script, but krakozyabry comes to the mail. Cyrillic does not want to. Html page itself in utf-8 + meta tag in utf-8.
Php file in the same utf-8 . Tried with and without BOM.
What's the secret?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2018-02-15
@evgen9586

Message encoding not set (Content-Type header).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question