title: wordpress: on send email save fields to database - error 500
body: <p>I am trying to save the contents of a submission form to a database table. But when I submit the form I receive error 500 without any debug error displaying. If I remove the line which inserts data to the table then the form is being sent without any errors.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>function send_mail($fields)
  {
      $subject = "New Quotation Form";
      $to = ["to@email.com"];
  
      extract($fields);
      ob_start();
      require 'email-template.php';
      $message = ob_get_contents();
  
      ob_end_clean();
  
      //insert quotation form contents to database table submitted_forms
      global $wbpd;
      $table = "submitted_forms";
      $data = array(
              'content' =&gt; $message,
              'datetime' =&gt; date("Y-m-d H:i:s"),
              'from_email' =&gt; $email
          );
  
      $ok = $wpdb-&gt;insert($table, $data); //it breaks here, if I remove it form is sent successfully
  
      if($wpdb-&gt;last_error !== '') :
  
          $str   = htmlspecialchars( $wpdb-&gt;last_error, ENT_QUOTES );
          $query = htmlspecialchars( $wpdb-&gt;last_query, ENT_QUOTES );
  
          print "&lt;div id='error'&gt;
          &lt;p class='wpdberror'&gt;&lt;strong&gt;WordPress database error:&lt;/strong&gt; [$str]&lt;br /&gt;
          &lt;code&gt;$query&lt;/code&gt;&lt;/p&gt;
          &lt;/div&gt;";
  
      endif;
  
      $replyTo =   "Reply-To: ".$email;
      $headers = array(
          'Content-Type: text/html; charset=UTF-8',
          $replyTo
      );
  
      file_put_contents("mail.html", $message);
  
      $sent = wp_mail($to, $subject, $message, $headers);
      return $sent;
  }
  </code></pre>