Home / Guide / Collegare moduli WordPress senza plugin SMTP | Lugatu
INTEGRAZIONE CMS · MASSIMA AFFIDABILITÀ · ZERO PLUGIN

Collegare moduli WordPress senza plugin SMTP | Lugatu

Velocizza il tuo sito WordPress eliminando i plugin SMTP instabili. Con Lugatu, inoltra le richieste direttamente tramite un’API REST scattante e sicura.

1. Perché i plugin SMTP per WordPress creano problemi

Plugin come WP Mail SMTP o Contact Form 7 richiedono continui aggiornamenti, appesantiscono il pannello di controllo e rischiano di bloccare la pagina se il server mail è lento.

2. Opzione A: Invio diretto dal browser nel tema

Inserisci un semplice modulo HTML nel tuo tema o blocco Gutenberg. I dati vengono trasmessi a Lugatu senza appesantire il database di 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. Opzione B: Inoltro tramite server con wp_remote_post()

Se vuoi convalidare i dati in PHP prima della trasmissione, inoltra la chiamata in modo autenticato con la tua chiave API privata.

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 di sicurezza e autenticazione

Sicurezza su WordPress: Memorizza la tua LUGATU_API_KEY nel file wp-config.php o nelle variabili d’ambiente del server, mai all’interno del tema.

Risoluzione dei problemi ed errori comuni di importazione

wp_remote_post restituisce timeout

Porta il valore di timeout a 15 secondi nei parametri di wp_remote_post e assicurati che l’hosting consenta chiamate HTTPS in uscita.

Domande frequenti

È richiesto un plugin specifico per creare i moduli?

No. Puoi impiegare HTML puro, Elementor, Divi o i tuoi template PHP personalizzati senza installare componenti aggiuntivi.

Pronto per creare l'endpoint del modulo?

Inizia gratuitamente in pochi secondi. Nessuna carta di credito richiesta.

Inizia gratis →