0

My order form stopped working ...it doesn't inserting data into the post-type orders as it should nor does it send me the email...i am using the plugin wp-mail-smtp to get it to send me the mails once an order is placed along with it trying to add the details of the order to the post-type order....but it does nothing however it does give the message thank you we contact you shortly.

<?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="myemail@gmail.com";
$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(); ?>

plz note i have multiple sites on single hosting plan

  • did you send the test e-mail? Is it working – Mukii kumar May 5 '17 at 4:45
  • inside the plugin it has send test mail that yes,.it working...but from form its not working – sonia k May 5 '17 at 4:52
  • which form you are using...? – Mukii kumar May 5 '17 at 4:57
0
/**
  * 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');
  }

Might be this will help you....If you can make edit to the core..Use this code if you are working with gravity forms.

  • no this code i put above is added to page template thts assigned to a page to act as a form – sonia k May 5 '17 at 5:04
  • Under mail section select the 'PHP mail()' function... – Mukii kumar May 5 '17 at 5:11
  • nop not working...plz note its not even adding the data to the posttype – sonia k May 5 '17 at 5:16
  • use die() and check where is the actual problem... – Mukii kumar May 5 '17 at 5:19
  • where do i put die(); – sonia k May 5 '17 at 5:22

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.