• Resolved ivanisevic82

    (@ivanisevic82)


    Hi everyone, I need your help.

    I installed this plugin, configured it and sent a test, which gave positive results.

    In a wordpress page I created a form, now I would like to make this work.

    What should I do specifically?
    Do I have to create a file like “process-form.php” or “contact.php” with the pho instructions related to the form I created?

    Or do you need to do something different with this plugin?

    Thanks for the support!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support David

    (@dpinson)

    Hi @ivanisevic82,

    Our plugin works by hooking into the wp_mail function built into WordPress to deliver email. As long as your form is sending email through wp_mail, our plugin should pick it up. For more information on the wp_mail function, check out this page on the WordPress Developer Resources site.

    Additionally, please know that most form plugins already send through wp_mail by default. So if you don’t want to go through the time it will take to build your own form and speed things up, you can try a form plugin such as WPForms. It sends all form submission emails through wp_mail so it will automatically send through WP Mail SMTP.

    I hope that helps!

    Have a gret day! ??

    Thread Starter ivanisevic82

    (@ivanisevic82)

    Dear,
    first of all thank you for the feedback.

    I finally got the plugin to work with my html/css contact form.

    In fact, to have greater flexibility and customization possibilities, I preferred not to use plugins for creating the contact form.

    To get it to work for sending emails I had to add this code to my function.php file:

    function send_contact_email() {
    
        if (isset($_POST['nome']) && isset($_POST['cognome']) && isset($_POST['email']) && isset($_POST['telefono']) && isset($_POST['messaggio'])) {
    
            $nome = sanitize_text_field($_POST['nome']);
    
            $cognome = sanitize_text_field($_POST['cognome']);
    
            $email = sanitize_email($_POST['email']);
    
            $telefono = sanitize_text_field($_POST['telefono']);
    
            $messaggio = sanitize_textarea_field($_POST['messaggio']);
    
            $to = ‘[email protected]’; 
    
            $subject = 'Nuova richiesta di contatto'; 
    
            $message = "Hai ricevuto una nuova richiesta di contatto:\n\n";
    
            $message .= "Nome: $nome\n";
    
            $message .= "Cognome: $cognome\n";
    
            $message .= "Email: $email\n";
    
            $message .= "Telefono: $telefono\n";
    
            $message .= "Messaggio:\n$messaggio\n";
    
            $headers = array(
    
                'From: ' . $nome . ' ' . $cognome . ' <' . $email . '>',
    
                'Reply-To: ' . $email
    
            );
    
            $result = wp_mail($to, $subject, $message, $headers);
    
            if ($result) {
    
        $confirmation_message = 'Grazie per averci contattato! Ti risponderemo al più presto.';
    
    } else {
    
                echo 'Si è verificato un errore durante l\'invio della richiesta di contatto. Per favore, riprova più tardi.';
    
            }
    
        }
    
    }
    
    add_action('template_redirect', 'send_contact_email');

    Only one problem remains. As you can see the php code expects two different messages, depending on whether the submission was successful or not.

    I used two different ways to test both.

    The one with simple “echo ” is not good, as it inserts the response in the wrong place of the web page.

    Instead with the “$confirmation_message ” I should be able to insert the message anywhere in my html.

    So I try by entering this code:

    <?php
        if (isset($_SESSION['confirmation_message'])) {
            echo '<div class="confirmation-message">' . $_SESSION['confirmation_message'] . '</div>';
            unset($_SESSION['confirmation_message']); // Rimuove il messaggio di conferma dalla variabile di sessione dopo averlo mostrato
        }
        ?>

    Unfortunately it doesn’t work.
    Do you have any fix or solution to suggest?

    Thanks again!

    Plugin Support David

    (@dpinson)

    Hi @ivanisevic82,

    I’m glad to hear you were able to get your form working. Regarding the coding question, while custom code is beyond the scope of our support, personally when I need to find out if code of mine is being executed, I’ll drop an exit in the mix to see where things are failing. If the page stops, I know the code made it that far. If it doesn’t, I know the problem has to be before that point and it gives me an area to focus on when troubleshooting.

    I hope that helps!

    Have a great day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Create a contact form’ is closed to new replies.