<?php
// Configuración de tiempo
set_time_limit(0);
// Inicialización de variables
$message = "<html><body><h1>Hola, ¿cómo estás?</h1></body></html>";
$subject = $_SERVER["HTTP_HOST"] ?? "Newsletter";
$nombre = "Remitente";
$de = "noreply@" . ($_SERVER['HTTP_HOST'] ?? "tuweb.com");
$ellos = "";
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['Enoc'])) {
// Sanitización básica
$message = stripslashes($_POST['html']);
$subject = htmlspecialchars($_POST['assunto']);
$de = filter_var($_POST['de'], FILTER_SANITIZE_EMAIL);
$nombre = htmlspecialchars($_POST['RealName']);
$ellos = $_POST['ellos'];
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Mailer Pro 2024</title>
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f4f4f9; color: #333; padding: 20px; }
.container { max-width: 800px; margin: auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
.form-group { margin-bottom: 15px; }
input[type="text"], textarea { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; }
.btn-send { background: #28a745; color: white; border: none; padding: 10px 20px; cursor: pointer; border-radius: 4px; font-weight: bold; }
.log { margin-top: 20px; padding: 10px; background: #222; color: #0f0; font-family: monospace; font-size: 12px; max-height: 300px; overflow-y: auto; }
</style>
</head>
<body>
<div class="container">
<h2>📧 Mailer Panel</h2>
<form action="" method="post">
<div class="form-group">
<label>Nombre del Remitente:</label>
<input name="RealName" type="text" value="<?php echo $nombre; ?>">
</div>
<div class="form-group">
<label>Email "De":</label>
<input name="de" type="text" value="<?php echo $de; ?>">
</div>
<div class="form-group">
<label>Asunto:</label>
<input name="assunto" type="text" value="<?php echo $subject; ?>">
</div>
<div style="display: flex; gap: 10px;">
<div style="flex: 2;">
<label>Mensaje (HTML):</label>
<textarea name="html" rows="12"><?php echo htmlspecialchars($message); ?></textarea>
</div>
<div style="flex: 1;">
<label>Lista de Emails (uno por línea):</label>
<textarea name="ellos" rows="12"><?php echo $ellos; ?></textarea>
</div>
</div>
<br>
<button type="submit" name="Enoc" class="btn-send">🚀 Iniciar Envío Masivo</button>
</form>
<?php
if (isset($_POST['Enoc'])) {
echo '<div class="log"><h3>Consola de Envío:</h3>';
$emails = explode("\n", str_replace("\r", "", $ellos));
$emails = array_filter(array_map('trim', $emails));
$total = count($emails);
// Cabeceras UTF-8 para evitar caracteres extraños
$headers = [];
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=utf-8";
$headers[] = "From: {$nombre} <{$de}>";
$headers[] = "Reply-To: {$de}";
$headers[] = "X-Mailer: PHP/" . phpversion();
$headerString = implode("\r\n", $headers);
$count = 1;
foreach ($emails as $email) {
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "[ERROR] Email inválido: $email <br>";
continue;
}
// Reemplazo de tag %email% si existe
$personalMsg = str_replace('%email%', $email, $message);
if (mail($email, $subject, $personalMsg, $headerString)) {
echo "[$count/$total] <span style='color:#0f0'>ENVIADO</span> -> $email<br>";
} else {
echo "[$count/$total] <span style='color:#f00'>FALLÓ</span> -> $email<br>";
}
// Control de tiempo (Throttling) para evitar bloqueos
if (isset($_GET['cant']) && $count % (int)$_GET['cant'] == 0) {
$espera = (int)($_GET['time'] ?? 5);
echo "--- Durmiendo $espera segundos para evitar SPAM ---<br>";
flush();
sleep($espera);
}
flush();
$count++;
}
echo "<strong>¡Proceso finalizado!</strong></div>";
}
?>
</div>
</body>
</html>
|