FIX config correo SMTP
This commit is contained in:
96
src/SMTP.php
Normal file
96
src/SMTP.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
class SMTP
|
||||
{
|
||||
public function __construct() {
|
||||
add_action('phpmailer_init', array($this, 'configure_smtp'));
|
||||
}
|
||||
|
||||
public static function text_email() {
|
||||
$to = get_field('admin_email');
|
||||
$subject = 'Prueba de configuración SMTP';
|
||||
$message = 'Este es un correo de prueba para verificar la configuración SMTP.';
|
||||
$headers = array('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
return wp_mail($to, $subject, $message, $headers);
|
||||
}
|
||||
|
||||
public function configure_smtp($phpmailer) {
|
||||
// error_log('✅ configure_smtp ejecutándose..............................');
|
||||
|
||||
// Usar get_option en lugar de get_field para campos de opciones
|
||||
$smtp_host = get_option('options_smtp_host');
|
||||
$smtp_port = get_option('options_smtp_port');
|
||||
$smtp_secure = get_option('options_smtp_secure');
|
||||
$smtp_auth = get_option('options_smtp_auth');
|
||||
$smtp_username = get_option('options_smtp_username');
|
||||
$smtp_password = get_option('options_smtp_password');
|
||||
$smtp_from_email = get_option('options_smtp_from_email');
|
||||
$smtp_from_name = get_option('options_smtp_from_name');
|
||||
|
||||
// Debug de todos los valores
|
||||
// error_log('📧 SMTP Config:');
|
||||
// error_log(' Host: ' . ($smtp_host ?: 'VACÍO'));
|
||||
|
||||
// Verificar si tenemos la configuración mínima necesaria
|
||||
if (empty($smtp_host) || empty($smtp_port)) {
|
||||
(error_log('🔴 host o port vacíos') );
|
||||
return; // Utilizar la configuración predeterminada de WordPress
|
||||
}
|
||||
|
||||
// Configurar el mailer para usar SMTP
|
||||
$phpmailer->isSMTP();
|
||||
$phpmailer->Host = $smtp_host;
|
||||
$phpmailer->Port = (int)$smtp_port;
|
||||
|
||||
// Autenticación
|
||||
$phpmailer->SMTPAuth = true;
|
||||
$phpmailer->Username = $smtp_username;
|
||||
$phpmailer->Password = $smtp_password;
|
||||
|
||||
// Tipo de seguridad (TLS/SSL)
|
||||
if (!empty($smtp_secure) && in_array($smtp_secure, ['ssl', 'tls'])) {
|
||||
$phpmailer->SMTPSecure = $smtp_secure;
|
||||
error_log('✅ Seguridad configurada: ' . $smtp_secure);
|
||||
}
|
||||
// Remitente
|
||||
if (!empty($smtp_from_email)) {
|
||||
$phpmailer->From = $smtp_from_email;
|
||||
$phpmailer->Sender = $smtp_from_email;
|
||||
error_log('✅ From Email configurado: ' . $smtp_from_email);
|
||||
}
|
||||
if (!empty($smtp_from_name)) {
|
||||
$phpmailer->FromName = $smtp_from_name;
|
||||
}
|
||||
|
||||
// ACTIVAR DEBUG TEMPORAL
|
||||
// $phpmailer->SMTPDebug = 2;
|
||||
// $phpmailer->Debugoutput = function($str, $level) {
|
||||
// error_log("SMTP Debug [$level]: $str");
|
||||
// };
|
||||
|
||||
// Configuraciones adicionales que pueden ayudar
|
||||
//$phpmailer->SMTPAutoTLS = true;
|
||||
$phpmailer->Timeout = 30;
|
||||
|
||||
error_log('✅ Configuración SMTP aplicada correctamente');
|
||||
}
|
||||
}
|
||||
|
||||
$smtp_acf_config = new SMTP();
|
||||
|
||||
function enviar_correo_smtp($to, $subject, $message, $attachments = []) {
|
||||
$headers = ['Content-Type: text/html; charset=UTF-8'];
|
||||
$send = wp_mail($to, $subject, $message);
|
||||
var_dump($send);
|
||||
return $send;
|
||||
}
|
||||
|
||||
/*
|
||||
enviar_correo_smtp(
|
||||
'hola@estudionexos.com',
|
||||
'Asunto del mensaje',
|
||||
'<p>Contenido del mensaje en HTML</p>'
|
||||
);
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user