The function works, but no data is received by the mail. I would like your view on this code.

Low bow!

<?php if (isset($_POST['submit'])) { $to = 'me@example.com'; $subject = 'Обратная связь'; $message = ' <html> <head> <title>'.$subject.'</title> </head> <body> <p>Имя: '.htmlspecialchars($_POST['fname']).'</p> <p>E-mail: '.htmlspecialchars($_POST['femail']).'</p> <p>Сообщение: '.htmlspecialchars($_POST['fcomment']).'</p> </body> </html>'; $headers = "Content-type: text/html; charset=utf-8\r\n"; mail($to, $subject, $message, $headers); header("Location: http://www.example.com/thankyou.html"); } 
  • and do not come in spam? - Kostiantyn Okhotnyk
  • and there is nothing in spam either ( - forzenson
  • And in the error log on the server, too, nothing? In the mail server log? - sanmai
  • check sending mail - create a separate php file with $ data = "test test test"; if (mail ("your email", "test", $ data)) {echo 'Send'; } else {echo 'not send'; } - Alex
  • Aleh, checked not working - forzenson

2 answers 2

The problem may be in the disabled functionality of the mail itself, some hosters simply disable the function or send it letters, so that users simply do not send letters from the hoster mailer.

To send good letters, it is better to use a third-party mailer - Yandex, Google, etc., or your corporate, if it exists. After registering on all known, there is access via TLS via POP3, SNTP, IMAP, settings (server address and port), see the selected mailer, for example for Yandex , for Google . At work I once set up mail for the domain ( https://pdd.yandex.ru/ ) of the organization, started a mailing box, connected a mailing list to it with a script - and there were no more problems. Letters are good, signed, do not get into spam.

You can use PHPMailer to send emails directly. Small, convenient, can do everything in most cases + attach files. Code examples for the same link, examples.

If the problem persists, use the debug flag in the PHPMailer class, it will output very detailed information about what is happening. Helps to catch 90% of problems.

    There are two main problems:

    1. Hosting (obviously, free) blocks sending emails so that you do not send any spam. Almost all free (and some paid) hosting do so.

    2. Many hosting providers that allow the use of the mail () php function block the sending of any content except text. You are trying to send html-code.

    If you are sure that your hosting allows you to send emails, try sending just a line of text, without markup.