ajax form
-
Hi,
I’m trying to send an email true a ajax contact form, but something seems to be wrong. I see the ajax load the right file (mail.php) but still it doesn’t send the email.
I have 4 different files for this action:
– form
– default.js
– mail.php
– functions.phpform:
<form id="contact_form" action="" method="POST"> <input id="name" type="text" name="name"> <input id="email" type="email" name="email"> <select id="location" name="location"> <?php $args = array('post_type' => 'locatie'); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); echo '<option value="'.get_the_title().'">'.get_the_title().'</option>'; endwhile; ?> </select> <select id="type" name="type"> <option value="huren">Huren</option> <option value="adverteren">Adverteren</option> </select> <textarea id="message" name="message">Opmerkingen en/of vragen</textarea> <input id="submit" type="submit" value="Verzenden"> </form>
default.js
jQuery('#contact_form').submit(ajaxSubmit); function ajaxSubmit(){ jQuery.ajax({ type:"POST", cache: false, url: "/wp-content/themes/test/mail.php", data: $('#contact_form').serialize(), dataType: "html", success:function(data){ alert(data); } }); return false; }
mail.php
<?php contact_send_message(); ?>
functions.php
function contact_send_message() { $contact_errors = false; $name = $_POST["name"]; $email = $_POST["email"]; $message = $_POST["message"]; $type = $_POST["type"]; $location = $_POST["location"]; $header .= "From: ". $name ." <".$email.">"; $message .= "Naam: $vname" . "\r\n"; $message .= "E-mail: $email" . "\r\n"; $message .= "Type: $type" . "\r\n"; $message .= "Locatie: $location" . "\r\n"; $message .= "Vraag en/of opmerking: $message"; $subject = "e-mail via test.be"; $subject = "=?utf-8?B?" . base64_encode($subject) . "?="; $to = "[email protected]"; wp_mail($to, $subject, $message, $header); if( !wp_mail($to, $subject, $message, $header) ) { $contact_errors = true; } } add_action('contact_send_message', 'contact_send_message');
Any idea what’s wrong?
Thanks
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘ajax form’ is closed to new replies.