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 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" />


jQuery(document).ready(function() {  
            type: 'POST',  
            url: '<?php echo admin_url('admin-ajax.php');?>',  
            data: {  
                action: 'evetheme_subconfor'
            success: function(data, textStatus, XMLHttpRequest){  
            error: function(MLHttpRequest, textStatus, errorThrown){  

PHP Script (now in 'functions.php', not 'inc/email.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);

        evetheme_sendmail( $name, $email, $website, $ip, $akismet->isCommentSpam(), $message);

// 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.

  • Just to make sure the mail system is working, did you try setting up and testing Contact-form-7 or similar? Is mail sent from the server reaching recipients? What is /inc/email.php and why are you using it for ajax instead of wp-admin ajax? – NoBugs Sep 9 '14 at 2:59
  • I will test Contact Form 7 today. I have tested by adding users to the system, which I believe would be the same thing, although I have tried via the PHP mail() function in the mailer script with the same results. 'inc/email.php' is the PHP mailer script above, and I didn't even know that there was a wp-admin ajax function. I do know there is the jQuery ajax function, so I used that instead. – Nate Sep 9 '14 at 7:44
  • It isn't jQuery either-or WP ajax, wp ajax is a certain file called to run anything with a certain wp_ajax_action hook - see codex.wordpress.org/AJAX_in_Plugins – NoBugs Sep 10 '14 at 4:16
  • I've tried CF7 and that works fine, emails come through without issue. I have since used the code from this answer (stackoverflow.com/questions/15492458/…, my code will be posted above shortly) and it tells me that there is a 500 server error when opening the admin-ajax.php file. When I used my original script (with fixed variables, not ones from the datebase), using wp_mail() also threw up a 500 server error, but mail() was fine. I think, because there was no reference file within that script, wp_mail() wouldn't have worked, correct? – Nate Sep 10 '14 at 23:57
  • 500 usually means you have a php error, check your error log – Mark Kaplun Sep 11 '14 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.