2013-08-06 33 views
0

我已经为联系表单做了wordpress短代码,我的表单显示并发送正常,但由于某种原因,它不显示我的错误或消息是否发送?联系表发送但没有显示错误或成功消息

  <?php 
      /* 
      Plugin Name: contact_shortcode 
      Plugin URI: http://nathanrobjohn.com 
      Description: contact form. Usage: <code>[contact email="[email protected]"]</code> 
      Version: 1.0 
      Author: Nathan Robjohn 
      Author URI:http://nathanrobjohn.com 
      */ 


      function nathan_shortcode_contact($atts, $content = null) { 


       extract(shortcode_atts(array(
        'email' => get_bloginfo('admin_email') 
       ), $atts)); 

        $content .= ' 
        <script type="text/javascript"> 
         var $j = jQuery.noConflict(); 
         $j(window).load(function(){    
          $j("#contact-form").submit(function() { 
           // validate and process form here 
           var str = $j(this).serialize();     
            $j.ajax({ 
            type: "POST", 
            url: "' . get_stylesheet_directory_uri() . '/short/sendmail.php", 
            data: str, 
            success: function(msg){      
             $j("#note").ajaxComplete(function(event, request, settings) 
             { 
              if(msg == "OK") // Message Sent? Show the Thank You message and hide the form 
              { 
               result = "Your message has been sent. Thank you!"; 
               $j("#fields").hide(); 
              } 
              else 
              { 
               result = msg; 
              }         
              $j(this).html(result);       
             });     
            }      
           });      
           return false; 
          });   
         }); 
        </script>'; 

          // now we put all of the HTML for the form into a PHP string 
        $content .= '<div id="post-a-comment" class="span12 contactform">'; 
         $content .= '<div id="fields">'; 
          $content .= '<h1>Enquire</h1>'; 
         $content .= '<div id="note"></div> <!--notification area used by jQuery/Ajax -->'; 
          $content .= '<form id="contact-form" action="">'; 
           $content .= '<input name="to_email" type="hidden" id="to_email" value="' . $email . '"/>'; 
           $content .= '<p class="span2">'; 
            $content .= '<label class="error" for="name">Name *</label>'; 
            $content .= '<input name="name" type="text" id="name"/>'; 
           $content .= '</p>'; 
           $content .= '<p class="span2">'; 
            $content .= '<label for="email">Phone number *</label>'; 
            $content .= '<input name="phone" type="text" id="phone"/>'; 
           $content .= '</p>'; 
           $content .= '<p class="span2">'; 
            $content .= '<label for="subject">Best time to call</label>'; 
           $content .= '<select name="time" id="subject" role="select" aria-required="true"> 
              <option></option> 
              <option>Morning</option> 
              <option>Afternoon</option> 
              <option>Anytime</option> 
             </select> ';    
           $content .= '</p>';  
           $content .= '<p class="span2">'; 
            $content .= '<label for="email">E-mail address *</label>'; 
            $content .= '<input name="email" type="text" id="email"/>'; 
           $content .= '</p>'; 
            $content .= '<p><label for="email">Enquiry message *</label></p>'; 
           $content .= '<p class="span12"><textarea rows="16" cols="" name="message"></textarea></p>'; 
           $content .= '<input type="submit" value="Submit" class="button" id="contact-submit" />'; 
          $content .= '</form>'; 
         $content .= '</div><!--end fields-->'; 
        $content .= '</div>'; 
       return $content; 
      } 
      add_shortcode('contact', 'nathan_shortcode_contact'); 

是我contactform.php上述

现在这是我的sendmail.php

  <?php 
      $plugin_name = 'contact_shortcode'; 


      function ValidateEmail($email) 
      { 
       /* 
       (Name) Letters, Numbers, Dots, Hyphens and Underscores 
       (@ sign) 
       (Domain) (with possible subdomain(s)). 
       Contains only letters, numbers, dots and hyphens (up to 255 characters) 
       (. sign) 
       (Extension) Letters only (up to 10 (can be increased in the future) characters) 
       */ 

       $regex = '/([a-z0-9_.-]+)'. # name 

       '@'. # at 

       '([a-z0-9.-]+){2,255}'. # domain & possibly subdomains 

       '.'. # period 

       '([a-z]+){2,10}/i'; # domain extension 

       if($email == '') { 
        return false; 
       } 
       else { 
        $eregi = preg_replace($regex, '', $email); 
       } 

       return empty($eregi) ? true : false; 
      } 

      $post = (!empty($_POST)) ? true : false; 

      if($post) 
      { 
       $name = stripslashes($_POST['name']); 
       $time = stripslashes($_POST['time']); 
       $phone = stripslashes($_POST['phone']); 
       $subject = 'Contact Form'; 
       $email = trim($_POST['email']); 
       $to = trim($_POST['to_email']); 
       $message = stripslashes($_POST['message']); 
       $error = ''; 

       // Check name 

       if(!$name) 
       { 
        $error .= 'Please enter your name.<br />'; 
       } 

       if(!$phone) 
       { 
        $error .= 'Please enter a phone number.<br />'; 
       } 

       if(!$time) 
       { 
        $error .= 'Please select a time.<br />'; 
       } 

       // Check email 

       if(!$email) 
       { 
        $error .= 'Please enter an e-mail address.<br />'; 
       } 

       if($email && !ValidateEmail($email)) 
       { 
        $error .= 'Please enter a valid e-mail address.<br />'; 
       } 

       // Check message (length) 

       if(!$message || strlen($message) < 15) 
       { 
        $error .= "Please enter your message. It should have at least 15 characters.<br />"; 
       } 

       if(!$error) // send email 
       { 
        $contents = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nPhone: $phone \n\nTime: $time \n\nMessage:\n $message"; 
        $mail = mail($to, $subject, $contents, 
         'From: '.$name.' <'.$email.'>\r\n' 
         .'Reply-To: '.$email.'\r\n' 
         .'X-Mailer: PHP/' . phpversion()); 

        if($mail) 
        { 
         echo 'OK'; 
        } 

       } 
       else 
       { 
        echo '<div class="notification_error">'.$error.'</div>'; // set up error div for jQuery/Ajax 
       } 

      } 
      ?> 

链接到活动网站http://auto.nathanrobjohn.com/contact-us/

出于某种原因的联系方式现在已经不再发送到

回答

0

您需要包含wp-load.php为了使用核心WordPress功能。

使用此您所放置sendmail.php在你的插件文件夹wp-content/plugins/yourplugin文件夹中

require('../../../wp-load.php'); 
相关问题