Contact form won't submit
I posted this on the Stackoverflow site and haven't received much assistance with the issue. I hope that, by reposting it on here, someone could please offer me any assistance.
I am creating a theme in Wordpress, using an Akismet form and a jQuery AJAX script (now using a new script). I have modified all of the relevant areas to integrate into my Wordpress site, even using the Akismet API key that is already there from the Akismet plugin. Here is my code:
Form
form method="post" id="contact_form"
input id="name" type="text" name="name" tabindex="1"/ label for="name"Name/label
input id="email" type="text" name="email" tabindex="2"/ label for="email"E-mail/label
input id="website" type="text" name="website" tabindex="3" value="http://" / label for="website"Website/label
textarea id="message" tabindex="4" rows="10" cols="60" name="message"/textarea
input type="submit" value="Send E-mail" tabindex="5" /
/form
jQuery
script
jQuery(document).ready(function() {
jQuery("#contact_form").submit(function(){
jQuery.ajax({
type: 'POST',
url: '?php echo admin_url('admin-ajax.php');?',
data: {
action: 'evetheme_subconfor'
},
success: function(data, textStatus, XMLHttpRequest){
alert(data);
},
error: function(MLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}
});
});
});
/script
PHP Script (now in 'functions.php', not 'inc/email.php')
?php
include (TEMPLATEPATH . 'inc/Akismet.class.php'); // Using require seems to stop the page from loading, but include seems to show the page.
function evetheme_sendmail( $name, $email, $website, $ip, $is_spam, $message) {
$subject = '';
if( $is_spam == true )
$subject = "[SPAM?]";
$subject .= "[Your_site.com] E-mail received from ".$name."//".$email;
// wp_mail( get_option('admin_email'), '[WP] ' . $subject, $message, 'From: '. $name . ' ' . $email . '');
mail( get_option('admin_email'), '[PHP]' . $subject, $message, 'From: '. $name . ' ' . $email . '');
}
function evetheme_subconfor(){
foreach($_POST as $key=$value)
$key = $value;
$wp_key = get_option( 'wordpress_api_key' );
$our_url = get_bloginfo( 'url' );
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$message = $_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];
$akismet = new Akismet($our_url, $wp_key);
$akismet-setCommentAuthor($name);
$akismet-setCommentAuthorEmail($email);
$akismet-setCommentAuthorURL($website);
$akismet-setCommentContent($message);
$akismet-setUserIP($ip);
evetheme_sendmail( $name, $email, $website, $ip, $akismet-isCommentSpam(), $message);
die();
}
// creating Ajax call for WordPress
add_action('wp_ajax_nopriv_evetheme_subconfor', 'evetheme_subconfor');
add_action('wp_ajax_evetheme_subconfor', 'evetheme_subconfor');
I have tried numerous things to get this to send emails to me. I have tried replacing the get_option('admin_email')
, get_option('wordpress_api_key')
and get_bloginfo('url')
references with their respective values, but I am not receiving any emails from the script. I have tested by adding a new user to the site and the problem seems limited to the script, as I am receiving emails from the wp_mail
function via Contact Form 7 and the main system. Could someone please help me? I am getting to my wits end here. I have tried including the form submission script on the page itself and calling it, both in the jQuery script and in the form via the action
attribute, but in both instances it brings back a 400 server error for the permalinked page or a 500 server error on the admin-ajax.php page or with wp_mail()
. Note: Since using the new code, I have only had 500 server errors when loading the admin-ajax.php file, regardless of whether I use wp_mail() or mail(). I'm really lost and the only thing that is stopping me from giving up is I'm a stubborn so-and-so.