How to make custom form in WordPress also send data on admin email ?

How to make custom form in WordPress also send data on admin email ?

Note: Setup your SMTP detailes

don’t affair ! this will on time put this code in you template and click the url after this will genrate your table automatic, after this process you can delete this code.

global $wpdb;
$table_name = $wpdb->prefix . "contact_table";
$sql = "CREATE TABLE $table_name (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  name varchar(50) NOT NULL,
  email varchar(50) NOT NULL,
  number varchar(20) NOT NULL,
  city varchar(50) NOT NULL,
  message text NOT NULL,
  PRIMARY KEY  (id)
);";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );

Now make your Form


<form action="" method="post" class="contact-form" autocomplete="false">
   <div class="row">
      <div class="col-lg-6">
         <div class="form-group">
            <input type="text" name="name" placeholder="Name" class="form-control" required="">
         </div>
      </div>
      <div class="col-lg-6">
         <div class="form-group">
            <input type="number" name="number" placeholder="Mobile No" class="form-control" required="">
         </div>
      </div>
      <div class="col-lg-6">
         <div class="form-group">
            <input type="mail" name="email" placeholder="Email Address" class="form-control" required="">
         </div>
      </div>
      <div class="col-lg-6">
         <div class="form-group">
            <select class="form-select" name="city" aria-label="Default select example">
               <option value=""> City</option>
               <option value="city1">City 1</option>
               <option value="city2">City 2</option>
               <option value="city3">City 3</option>
            </select>
         </div>
      </div>
      <div class="col-lg-12">
         <div class="form-group">
            <textarea placeholder="How can we help?" name="message" class="form-control"></textarea>
         </div>
      </div>
      <div class="col-lg-10 pdt-4">
         <div class="form-groups">
            <figure>
               <img src="<?php echo bloginfo('template_url') ?>/images/contact-robot.svg" alt="image" class="img-fluid">
            </figure>
         </div>
      </div>
      <div class="col-lg-2 pdt-3">
         <div class="form-groups">
            <p>* Indicates Mandatary Field</p>
         </div>
         <div class="button-form">
            <button type="Submit"value="Submit" class="hover">
            Submit
            </button>
         </div>
      </div>
   </div>
</form>
To Top