FIX config correo SMTP
This commit is contained in:
@@ -12,9 +12,11 @@ namespace App;
|
|||||||
use Routes;
|
use Routes;
|
||||||
use Timber\Timber;
|
use Timber\Timber;
|
||||||
|
|
||||||
// Load Composer dependencies.
|
require_once __DIR__ . '/src/SMTP.php'; //config email
|
||||||
require_once __DIR__ . '/vendor/autoload.php';
|
require_once __DIR__ . '/vendor/autoload.php'; // Load Composer dependencies.
|
||||||
|
|
||||||
Timber::init();
|
Timber::init();
|
||||||
|
|
||||||
$site = new StarterSite();
|
$site = new StarterSite();
|
||||||
|
|
||||||
// Ruta para la página de 'noticias'
|
// Ruta para la página de 'noticias'
|
||||||
@@ -48,3 +50,47 @@ foreach(['/es/noticias/conflictos-laborales/page/:paged','/eu/berriak/lan-gatazk
|
|||||||
Routes::load('archive-conflictos-laborales.php', $params, $query, 200);
|
Routes::load('archive-conflictos-laborales.php', $params, $query, 200);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// *************************DEBUGUEANDO...................
|
||||||
|
|
||||||
|
// add_shortcode('test_smtp_db', function() {
|
||||||
|
// global $wpdb;
|
||||||
|
|
||||||
|
// $output = '<h3>Verificación directa en BD:</h3>';
|
||||||
|
|
||||||
|
// // Buscar en la tabla wp_options todas las entradas que contengan 'smtp'
|
||||||
|
// $results = $wpdb->get_results("
|
||||||
|
// SELECT option_name, option_value
|
||||||
|
// FROM {$wpdb->options}
|
||||||
|
// WHERE option_name LIKE '%smtp%'
|
||||||
|
// ORDER BY option_name
|
||||||
|
// ");
|
||||||
|
|
||||||
|
// if ($results) {
|
||||||
|
// $output .= '<ul>';
|
||||||
|
// foreach ($results as $row) {
|
||||||
|
// $value = strlen($row->option_value) > 100 ? substr($row->option_value, 0, 100) . '...' : $row->option_value;
|
||||||
|
// $output .= '<li><strong>' . $row->option_name . ':</strong> ' . esc_html($value) . '</li>';
|
||||||
|
// }
|
||||||
|
// $output .= '</ul>';
|
||||||
|
// } else {
|
||||||
|
// $output .= '<p>❌ No se encontró ninguna opción con "smtp" en la base de datos</p>';
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Probar diferentes variaciones
|
||||||
|
// $output .= '<h4>Pruebas de get_option:</h4><ul>';
|
||||||
|
// $variations = [
|
||||||
|
// 'smtp_host',
|
||||||
|
// 'options_smtp_host',
|
||||||
|
// '_smtp_host',
|
||||||
|
// 'configuracion-smtp-correo_smtp_host'
|
||||||
|
// ];
|
||||||
|
|
||||||
|
// foreach ($variations as $key) {
|
||||||
|
// $value = get_option($key);
|
||||||
|
// $output .= '<li><strong>' . $key . ':</strong> ' . ($value ? esc_html($value) : '❌ VACÍO') . '</li>';
|
||||||
|
// }
|
||||||
|
// $output .= '</ul>';
|
||||||
|
|
||||||
|
// return $output;
|
||||||
|
// });
|
||||||
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