For some reason, the php script does not send data to the mail. I even made a record in the file to get the data received, but the recording does not occur. Did I do something wrong?

<?php // config $adminemail="andrewdymov@gmail.com"; $date=date("dmy"); $time=date("H:i"); // confirm data $name = $_POST["name"]; $email = $_POST["mail"]; $subject = $_POST["subject"]; $message = $_POST["message"]; if (!preg_match("/.+@.+\..+/i", strtolower($email))) { header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500); } else { $msg="<p>Отправлено: $time $date</p> <p>Имя: $name</p> <p>E-mail: $email</p> <p>Тема: $subject</p> <p>Сообщение: $message</p>"; mail("$adminemail", "$subject", "$msg"); $fp = fopen("test.txt", "a"); // Открываем файл в режиме записи $test = fwrite($fp, $msg); } ?> 
  • Often an error with the server itself, are you on a local machine or a shared host? in terms of code everything is OK - Robert Sinclair
  • I have a VPS. Ubuntu 16.04, nginx proxies Apache. - JamesJGoodwin
  • What response code does the server return? Do you have rights to write test.txt? - Firepro
  • @Firepro If I send the correct email-address, then it passes the regular schedule and returns 200. If I send a deliberately incorrect email, it returns 500 as intended. That is, the data reaches the script, but for some reason they are not written to the file / are not sent to the mail. - JamesJGoodwin
  • var_dump ($ test); - at the end, substitute, and see what displays you if you enter a normal email? If false, you need to set permissions; if> 0, the record is successful. Mail is not sent because your mail server on the VPS is apparently not configured, look for sendmail or postfix configuration material, the latter is easier to configure. Also, you should not forget about SPF, PTR, DKIM, otherwise mail will be sent but not received, mail logs are usually in /var/log/mail.log - Firepro

1 answer 1

 mail($adminemail, $subject, $msg"); 

Try this