I am using WordPress, I have created a custom form. I have added the form code in the function.php and added the shortcode on the page.
Then I also created process.php in the theme folder and added the below code. I am able to insert the data in the table. There is no issue here.
<?php
define('BLOCK_LOAD', true);
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php' );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/wp-db.php' );
$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
global $wpdb; // <--- making $wpdb as global
if(isset($_POST['submit'])){
$data = $_POST;
$parentsdata= array(
'name' => sanitize_text_field($data['parentsname']),
'mobile' => sanitize_text_field($data['mobileno']),
'email' => sanitize_text_field($data['email']),
'agent_email' => sanitize_text_field($data['agent_email'])
);
$query=$wpdb->insert('wp_parent',$parentsdata,array('%s','%s','%s','%s'));
$lastid = $wpdb->insert_id;
$childdata= array(
'p_id' => $lastid,
'childname' => sanitize_text_field($data['childname']),
'childage' => sanitize_text_field($data['childage']),
'chldschoolname' => sanitize_text_field($data['nameofschool']),
'childgrade' => sanitize_text_field($data['childgread']),
);
if ($query) {
$query=$wpdb->insert('wp_child',$childdata,array('%s','%s','%s','%s','%s'));
$response['error'] = "true";
header('Location: /thank-you');
exit();
}else{
$response['error'] = "false";
}
}
?>
What I am doing is, I have to send the email to the user as well as the admin. I know using SMTP code or wp_mail I can send it but there are more changes to email going to spam.
I have installed the WordPress plugin called WP Mail SMTP by WPForms. Now my issue is how to connect the custom code with this plugin or any other plugin?