'; $c = true; $plain_text = ""; $table = ""; foreach ($_POST as $key => $value) { if (is_array($value)) $value = implode(", ", $value); if ($value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject") { // text/html $table .= (($c = !$c) ? '' : '') . ' ' . $key . ' ' . $value . ' '; // text/plain $plain_text .= $key . ": " . $value . "\r\n"; } } $html .= ' ' . $table . '
'; function adopt($text) { return "=?UTF-8?B?" . Base64_encode($text) . "?="; } $boundary = "--" . md5(uniqid(time())); // генерируем разделитель $headers = array( "MIME-Version" => "1.0", "Date" => date("r (T)"), "From" => "Пролок <" . $project_name . ">", "Reply-To" => $project_name, "X-Mailer" => "PHP/" . phpversion(), "Content-Type" => 'multipart/alternative; boundary="' . $boundary . '"', ); // Текстовая версия письма $message_plain_text .= "--$boundary" . "\n"; $message_plain_text .= "Content-Type: text/plain; charset=utf-8" . "\n"; $message_plain_text .= "Content-Transfer-Encoding: 8bit" . "\n\n"; $message_plain_text .= $form_subject . "\r\n" . $plain_text . "\n"; // HTML-версия письма $message_html .= "--$boundary" . "\n"; $message_html .= "Content-Type: text/html; charset=utf-8" . "\n"; $message_html .= "Content-Transfer-Encoding: 8bit" . "\n\n"; $message_html .= $html . "\n"; $multipart_alternative = $message_plain_text . $message_html . "--$boundary--" . "\n"; if (!mail($admin_email, adopt($form_subject), $multipart_alternative, $headers, "-f " . $project_name)) { $error = error_get_last()["message"]; print_r($error); echo $error; }