Home / Guías / Conectar formularios de WordPress sin plugins SMTP | Lugatu
INTEGRACIÓN CMS · MÁXIMA FIABILIDAD · CERO PLUGINS

Conectar formularios de WordPress sin plugins SMTP | Lugatu

Optimice su sitio WordPress eliminando plugins SMTP inestables. Con Lugatu, envíe las solicitudes directamente mediante una API REST ágil y sin mantenimiento.

1. Por qué fallan los plugins SMTP en WordPress

Plugins como WP Mail SMTP o Contact Form 7 exigen constantes actualizaciones, ralentizan el panel y pueden bloquear la web si el servidor SMTP falla.

2. Opción A: Envío directo desde el navegador

Incruste un formulario HTML en su tema o bloque Gutenberg. Los datos se envían a Lugatu sin sobrecargar la base de datos de WordPress.

functions.php php
<?php
// Secure WordPress server-side form forwarding
function handle_custom_contact_submission() {
    if ( ! isset( $_POST['contact_nonce'] ) || ! wp_verify_nonce( $_POST['contact_nonce'], 'contact_action' ) ) {
        wp_send_json_error( array( 'message' => 'Security check failed.' ), 403 );
    }

    // Silently drop automated spam if honeypot trap is filled
    if ( ! empty( $_POST['_gotcha'] ) ) {
        wp_send_json_success( array( 'message' => 'Thank you! Message received.' ) );
        return;
    }

    $name    = sanitize_text_field( $_POST['name'] ?? '' );
    $email   = sanitize_email( $_POST['email'] ?? '' );
    $message = sanitize_textarea_field( $_POST['message'] ?? '' );

    $payload = array(
        'fields' => array(
            'name'    => $name,
            'email'   => $email,
            'message' => $message,
        ),
    );

    $api_url = 'https://www.lugatu.com/api/v1/forms/' . LUGATU_FORM_GUID . '/submissions';

    $response = wp_remote_post( $api_url, array(
        'headers' => array(
            'Authorization'   => 'Bearer ' . LUGATU_API_KEY,
            'Content-Type'    => 'application/json',
            'Idempotency-Key' => wp_generate_uuid4(),
        ),
        'body'    => wp_json_encode( $payload ),
        'timeout' => 10,
    ) );

    if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) >= 400 ) {
        wp_send_json_error( array( 'message' => 'Failed to deliver message.' ), 500 );
    }

    wp_send_json_success( array( 'message' => 'Thank you! Message received.' ) );
}
add_action( 'wp_ajax_custom_contact', 'handle_custom_contact_submission' );
add_action( 'wp_ajax_nopriv_custom_contact', 'handle_custom_contact_submission' );

3. Opción B: Transmisión desde el servidor con wp_remote_post()

Si prefiere validar los datos en PHP antes de enviarlos, transmita la consulta de forma segura utilizando su clave API privada.

wordpress-embed.html html
<iframe
  src="https://www.lugatu.com/embed/forms/YOUR_PUBLIC_FORM_ID"
  width="100%"
  height="540"
  frameborder="0"
  style="border:none; border-radius:16px; overflow:hidden;"
  title="Contact Form">
</iframe>

Invariante de seguridad y autenticación

Seguridad en WordPress: Defina su LUGATU_API_KEY en wp-config.php o en variables de entorno del servidor, jamás dentro del código fuente del tema.

Solución de problemas y errores comunes de ingesta

wp_remote_post devuelve timeout

Aumente el parámetro timeout a 15 segundos en wp_remote_post y compruebe que su hosting permita conexiones HTTPS salientes.

Preguntas frecuentes

¿Debo tener instalado algún plugin específico de formularios?

No. Puede usar HTML puro, Elementor, Divi o sus propias plantillas PHP sin ningún plugin extra.

¿Listo para crear el punto final de su formulario?

Comience gratis en segundos. No se requiere tarjeta de crédito.

Comience gratis →