<?php $adminemail="post-adress@mail.ru"; //email $name=$_POST['name']; // получаем данные $email=$_POST['email']; $subject=$_POST['subject']; $message=$_POST['message']; $header = "MIME-Version: 1.0\r\n"; $header .= "Content-type: text/html; charset=utf-8\r\n"; $header .= "From: Antwerp-Diamonds <Antwerp-diamonds@mail.ru>"; $msg=" // формируем сообщение <b>Имя:</b> $name <br/> <b>E-mail:</b> $email <br/> <b>Заглавие:</b> $subject <br/> <b>Сообщение:</b> $message <br/> "; mail("$adminemail", "Сообщение от $name", "$msg", "$header"); // отправляем if ($mail) {exit("Письмо успешно отправлено!");} // выводим сообщение else {exit("Письмо успешно отправлено!");} exit; ?> 

Should send letters to mail.ru mail. Works through time - do not come letters. I noticed a certain dependence of the success of sending on what you enter in the fields, but I'm not exactly sure. The file "mail.php" in UTF8 encoding.

  • one
    What is the title coming from the mail.ru server to letters that are not delivered? Web server configured for the correct distribution of letters? There are a number of requirements that must be met for successful delivery. - Invision
  • I did not quite understand "What is the header coming from the mail.ru server to letters that are not delivered?". The letter is not delivered to the post office simply, and after sending it all the same, "The letter has been sent successfully!" - Alexander
  • Web server did not configure, I do not know how. - Alexander
  • one
    Then read the manuals on how to get detailed information from mail servers during mailing and how to set up your server for mailing. Or better use the services of third-party smtp companies. For example mandrillapp.com or sendgrid.com Single tariffs, letters will reach and will not go to spam * - Invision

1 answer 1

I made this working version.

 <?php /* base */ $to = YOUR_POST@Mail.Ru; $project_name = 'PROJECT_NAME'; $subject = "Contact_form"; /* fields */ $f_name = $_POST["name"]; $f_phone = $_POST["phone"]; $f_email = $_POST["email"]; $f_message = $_POST["message"]; /* msg */ $message = '<html><body>'; $message .= '<table border="1" bgcolor="#F8F8F8" width="100%">'; $message .= '<tr><td colspan="2" style="padding: 5px 10px; text-align:center;">Контакты</td></tr>'; $message .= '<tr> <td width="30%" style="padding: 5px 10px;">ФИО:</td> <td style="padding: 4px 8px;">'.$f_name.'</td> </tr>'; $message .= '<tr> <td width="30%" style="padding: 5px 10px;">Телефон:</td> <td style="padding: 4px 8px;">'.$f_phone.'</td> </tr>'; $message .= '<tr> <td width="30%" style="padding: 5px 10px;">Е-майл:</td> <td style="padding: 4px 8px;">'.$f_email.'</td> </tr>'; $message .= '<tr> <td width="30%" style="padding: 5px 10px;">Сообщение:</td> <td style="padding: 4px 8px;">'.$f_message.'</td> </tr>'; $message .= '</table>'; $message .= '</body></html>'; /* header */ $headers = "Content-type: text/html; charset=utf-8 \r\n"; $headers .= 'From: ' . $project_name . '<'. $subject . '>'; if( mail( $to, $subject, $message, $headers ) ) { exit("Письмо отправлено!"); } else { exit("Произошла ошибка!"); } ?>