$to = $_GET['to'];
$from = $_GET['from'];
$subject = $_GET['subject'];
$message = $_GET['message'];
$attachment = $_GET['attachment'];
if (empty($to)) {
echo "Не указан получатель";
} else {
$boundary = uniqid();
$headers = "From: $from\r\n";
$headers .= "MIME-Version: 1.0\r\n";
if (!empty($attachment)) {
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
$file = file_get_contents($attachment);
$mime_type = mime_content_type($attachment);
$filename = basename($attachment);
$body = "--$boundary\r\n";
$body .= "Content-Type: text/html; charset=utf-8\r\n";
$body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$body .= "$message\r\n";
$body .= "--$boundary\r\n";
$body .= "Content-Type: $mime_type; name=\"$filename\"\r\n";
$body .= "Content-Disposition: attachment; filename=\"$filename\"\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n";
$body .= "\r\n";
$body .= chunk_split(base64_encode($file));
$body .= "--$boundary--\r\n";
} else {
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$body = "$message\r\n";
}
$mail = mail($to, $subject, $body, $headers);
if ($mail) {
echo 'success';
} else {
ech
o '{"status":"Ошибка!"}';
}
}