At your site you need to make a submission from the form. Long tormented with PHP and Ajax, but could not figure it out.

I tried this code, but when I click on the "Send" button, nothing comes to the mail.

<? if((isset($_POST['name'])&&$_POST['name']!="")&&(isset($_POST['phone'])&&$_POST['phone']!="")){ $to = 'mail@yandex.ru'; $subject = 'Обратный звонок'; $message = ' <html> <head> <title>'.$subject.'</title> </head> <body> <p>Имя: '.$_POST['name'].'</p> <p>Телефон: '.$_POST['phone'].'</p> </body> </html>'; //Текст нащего сообщения можно использовать HTML теги $headers = "Content-type: text/html; charset=utf-8 \r\n"; $headers .= "From: Отправитель <from@example.com>\r\n"; mail($to, $subject, $message, $headers); } ?> 
  • And where is the ajax sending code? And check if the letters come from php at all, maybe you don't have an email client installed. - Artem Gorlachev
  • Add output echo 'test'; before if and check if it returns ajax. Perhaps Ajax does not send data. Or, as they wrote the above problems with mail () - Sergey Omelchenko

3 answers 3

Maybe you have not installed or not configured SMTP, or mail service filters the message as spam. It is better to use a library like phpmailer

    As mentioned above, you may not have configured SMTP. Perhaps you are placing your site on a free hosting thread, for example, and due to certain circumstances, you are immediately marked as spam and so on. Tip: try to first send only plain text, without any html there. If within 30 minutes nothing has come, read the logs, it will be clear if the letters are sent at all. If the server is not yours, and you take hosting, write to those who support it and clarify something.

      Used the same script. Letters were not sent while the script was in a separate file. When I moved it to index.php, everything worked ... But this is certainly not a solution.