不会将表单详细信息添加到数据库或给我发送邮件

时间:2017-05-05 作者:sonia k

我的订单已停止工作。。。它不会像应该的那样将数据插入post类型的订单中,也不会向我发送电子邮件。。。我正在使用插件wp mail smtp让它在下订单后向我发送邮件,并尝试将订单的详细信息添加到post类型订单中。。。。但它什么都不做,但它确实会传递一条信息,谢谢,我们会很快与您联系。

<?php get_header(); ?>

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript">
  $(function submitorder() {
    $( "#dialog-message" ).dialog({
      modal: true,
      buttons: {
        Ok: function() {
          $( this ).dialog( "close" );
          window.location = "http://mytestsite.org/order";
        }
      }
    });
  });


  </script>

<article class="col-xs-12 col-sm-12 col-md-12 col-lg-12 ">

<div class="col-xs-offset-1 col-xs-10 col-sm-offset-1 col-sm-10 col-md-offset-4 col-md-4 col-lg-offset-4 col-lg-4 text-center bottom-pad">
<div class="text-center">
 <form action="" method="post" class="form-horizontal formpad " >       

    <div class="form-group">            
            <div class="col-sm-12 col-md-12 col-lg-12">
                <input type="text" id="inputName" name="leadname" placeholder="Name" class="form-control" height="34px">
            </div>
        </div> 

        <div class="form-group">
                <div class="col-sm-12 col-md-12 col-lg-12">
                <input type="text" id="inputEmail" name="leademail" placeholder="Email" class="form-control"  height="34px">
            </div>
        </div>  


        <div class="col-sm-12 col-md-12 col-lg-12">
        <label class="text-left">Order Type</label> 
        </div>
         <div class="form-group">

            <div class="col-sm-6 col-md-6 col-lg-6 text-left">
                <input type="checkbox" value="0" name="order_type[]"> pens</input><br>
                <input type="checkbox" value="1" name="order_type[]"> books</input><br>
                <input type="checkbox" value="2" name="order_type[]"> papers</input><br>
                <input type="checkbox" value="3" name="order_type[]"> pencils</input><br>
            </div>
        </div>


        <div class="form-group ">
            <div class="col-sm-12 col-md-12 col-lg-12">
                <button type="submit" name="submit" class="btn order-btn" onclick="submitorder();"><strong>Order Now!</strong></button>
            </div>
        </div>

    </form>
 </div>
</div>

</article> 

<?php

$toemail="[email protected]";
$lead_name=$_POST[\'leadname\'];
$lead_email=$_POST[\'leademail\'];

$chk=array();
$planchk=array();
$headers=  \'From: \'.$lead_name.\'<\'.$lead_email .\'>\'. "\\r\\n" . \'Reply-To: \'.$lead_email;

if(isset($_POST[\'submit\']))
{
    global $wpdb;
        if (empty($lead_name))
    {   

?>
    <div id="dialog-message" title="Alert">
        <p>
            Please enter your Name.
        </p> 
    </div>

    <?php     

    }
        elseif (empty($lead_email))
    {
    ?>

    <div id="dialog-message" title="Alert">
        <p>             
            Please enter your email.
        </p> 
    </div>

    <?php

    }
        else
        {
        $todaydate = new DateTime();
        $todaydate =$todaydate->format(\'Y-m-d H-i-s\');
    $newpost= array(\'post_type\'=>\'orders\',
                        \'post_title\'=>$lead_name,
            \'post_author\'=>\'1\',
            \'post_status\'=>\'publish\',
            \'post_date\'=>$todaydate );
    global $wpdb;
    $wpdb->insert(\'wp_posts\',$newpost); 
    $newpostid=$wpdb->insert_id;
    update_field(\'lead_email\',$lead_email,$newpostid);


    if(!empty($_POST[\'order_type\']))
    {   
        foreach($_POST[\'order_type\'] as $selectedorder)
        {       
        $chk[]=$selectedorder;      
        }
        update_field(\'field_55efacbc25266\',$chk,$newpostid);        
    }   


?>

<div id="dialog-message" title="Thank You">
  <p>
        We will Contact you shortly
  </p> 
</div>


<?php
wp_mail($toemail,$selectedorder." ORDER query from " .$lead_name,"order",$headers);        
}
unset($_POST[\'submit\']);
}

?>

<?php get_footer(); ?>
请注意,我有多个网站的单一托管计划

1 个回复
SO网友:Mukii kumar

/**
  * Since the install of WP-Mail-SMTP we need to make sure the FROM is 
    the same as the one specified in the plugin
  * These filters will overwrite any FROM send by other plugins.
  */
 add_filter(\'wp_mail_from\',\'custom_wp_mail_from\');
 function custom_wp_mail_from($email) {
     return get_option(\'mail_from\');
  }

 add_filter(\'wp_mail_from_name\',\'custom_wp_mail_from_name\');
 function custom_wp_mail_from_name($name) {
    return get_option(\'mail_from_name\');
  }
也许这会帮助你。。。。如果可以对核心进行编辑。。如果使用重力表单,请使用此代码。