Contact form doesn’t send email after displaying string

this is a contact form plugin for my website in WordPress. The contact form should display a message if it’s similair to a string and then let the user decide if they still want to send the message.

The problem is the deliver_mail_now(); function sends the message but if I show the similair text message and user press send email (deliver_mail()) it doesn’t send the message even if it’s nearly the same function.

        function acf_similair() {
                   if ( isset( $_POST['button-submit'])) {      //The contact form submit button

                        $name    = sanitize_text_field( $_POST["name"] );
                        $email   = sanitize_email( $_POST["email"] );
                        $subject = sanitize_text_field( $_POST["subject"] );
                        $message = esc_textarea( $_POST["message"] );

                   $similair = '//';      

                   similar_text($similair, $message, $percent);
                   if ($percent > 50) {
                   echo '//';
                   echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
                   echo '<input type="submit" name="submit" id="submit" value="Send email">';
                   echo '</form>';
                   } else {
                    deliver_mail_now();
                   }

    function deliver_mail_now() {

                    $name    = sanitize_text_field( $_POST["name"] );
                    $email   = sanitize_email( $_POST["email"] );
                    $subject = sanitize_text_field( $_POST["subject"] );
                    $message = esc_textarea( $_POST["message"] );           

                    $to = get_option( 'admin_email' );
                    $headers = "From: $name <$email>" . "\r\n";

                    if ( wp_mail( $to, $subject, $message, $headers ) ) {
                        echo 'Success';
                    } else {    
                        echo 'Fail';
                    }
            }

function deliver_mail() {
        if ( isset( $_POST['submit'])) {
                    $name    = sanitize_text_field( $_POST["name"] );
                    $email   = sanitize_email( $_POST["email"] );
                    $subject = sanitize_text_field( $_POST["subject"] );
                    $message = esc_textarea( $_POST["message"] );           

                    $to = get_option( 'admin_email' );
                    $headers = "From: $name <$email>" . "\r\n";

                    if ( wp_mail( $to, $subject, $message, $headers ) ) {
                        echo 'Success';
                    } else {    
                        echo 'Fail';
                    }
        }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s