vendredi 28 avril 2017

PHP form sends multiple emails after submission

So I have created a PHP form for my wordpress site as Contact form 7 is too heavy and slows it down drastically.

But I have the same contact form on multiple 'items' on one page, so the contact form is used more than once on one page. So when the sender clicks submit depending on how many items are on the page the form will send the same amount of emails...

Now contact form 7 doesn't do this when you submit it only sends me one email. So there is a way to do it, I just don't know as I am new to PHP.

Any help would be great. Here is my sending form code but let me know if you need anything else. cheers guys:

// Sending form to admin
    if ($error == false) {
        // Hook to support plugin Contact Form DB
        //do_action( 'name_before_send_mail', $form_data );
        $to = $name_atts['email_to'];

        if ($name_atts['hide_subject'] != "true") {
            $subject = "(".get_bloginfo('name').") " . $form_data['form_subject'];
        } else {
            $subject = get_bloginfo('name');
        }
        $message = $form_data['form_name'] . "\r\n\r\n" . $form_data['form_email'] . "\r\n\r\n" . $form_data['form_message'] . "\r\n\r\n" . sprintf( esc_attr__( 'IP: %s' ), name_get_the_ip() ); 
        $headers = "Content-Type: text/plain; charset=UTF-8" . "\r\n";
        $headers .= "Content-Transfer-Encoding: 8bit" . "\r\n";
        $headers .= "From: ".$form_data['form_name']." <".$form_data['form_email'].">" . "\r\n";
        $headers .= "Reply-To: <".$form_data['form_email'].">" . "\r\n";

        if(wp_mail($to, $subject, $message, $headers) == true) { 
            $result = $name_atts['message_success'];
            $sent = true;
        } else {
            $result = $name_atts['message_error'];
            $fail = true;
        }       
    }




Aucun commentaire:

Enregistrer un commentaire