I
I
Ivan Nekrasov2018-08-09 21:41:19
PHP
Ivan Nekrasov, 2018-08-09 21:41:19

Can't submit completed forms via mail php?

$('.modal').on('hidden.bs.modal', function (e) {
    $('input:not(.type)', $(this)).val('');
  });
  $('form').submit(function(e){
      e.preventDefault();
    var form_data = {
      'name':$(".name", $(this)).val(),
      'tel':$(".tel", $(this)).val(),
      'price':$("#price", $(this)).val(),
      'square':$("#square", $(this)).val(),
      'type':$(".type", $(this)).val()
    };
    $.ajax({
      type: "POST",
      url: "mail.php",
      data: form_data,
      success: function(){
        $('.modal').modal('hide');
        setTimeout(function() {
        	$('.success').fadeToggle();
        }, 1000);
        setTimeout(function() {
        	$('.success').fadeToggle();
        }, 2500);
      },
      error: function() {
      	alert("Произошла какая то ошибка!");
      }
    });

Hello. Everything works for me, but the completed forms are not sent to email
Here is my mail.php
<?php

$to  = '[email protected]*****.ru' . ', '; // note the comma
$to .= '[email protected]*****.ru';


$subject = 'Birthday Reminders for August';


$tel = trim($_POST["tel"]);
$message = "Телефон: $tel\n";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";


$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";



mail($to, $subject, $message, $headers);
?>

If I just do text in $message, then everything comes great. How to send form data to email

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2018-08-09
@neenekrasov

I use this function for a similar task:

function mail_utf8($to, $from_user, $from_email, $subject = '(No subject)', $message = '')
{
    #base64_encode() - чтобы отображалась кириллица.
    $from_user = "=?UTF-8?B?".base64_encode($from_user)."?=";
    $subject = "=?UTF-8?B?".base64_encode($subject)."?=";
 
    $headers = "From: $from_user <$from_email>\r\n".
               "MIME-Version: 1.0" . "\r\n" .
               "Content-type: text/html; charset=UTF-8" . "\r\n";
 
    return mail($to, $subject, $message, $headers);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question