I have a WordPress site with getResponse plugin.
I have a registration form which should confirm the email of the user, then the user should be registered in the database.
I have an ajax call when the user submits the form, it gets the username and email to check if the email or username is already registered in the site.
The form html looks like this
<div id="td-register-div">
<div class="td_display_err"></div>
<form id="register-form" action="#" method="post">
<div class="td-login-input">
<input class="td-login-input" type="text" name="register_email" id="register_email">
<label for="register_email">Your Email</label>
</div>
<div class="td-login-input">
<input class="td-login-input" type="text" name="register_user" id="register_user">
<label for="register_user">Your Username</label>
</div>
<input type="button" name="register_button" id="register_buttonn" value="Register">
</form>
</div>
jQuery looks like this
$("#registerForm #register_buttonn").click(function(e){
e.preventDefault();
var user_email = $("#registerForm #register_email").val();
var user_name = $("#registerForm #register_user").val();
if (user_email == "" || user_name == "") {
$("#td-register-div > .td_display_err").html("Email and username required");
$("#td-register-div > .td_display_err").css("display", "block");
} else{
jQuery.ajax({
type: "post",
url: my_ajax_object.ajax_url,
data : {action: "user_register_ajax", user_email: user_email, user_name: user_name},
success: function(response){
$("#td-register-div > .td_display_err").css("display", "block");
$("#td-register-div > .td_display_err").html(response);
}
});
}
});
function.php looks like this
function user_register_ajax(){
global $wpdb;
//Get username and email
$user_email = $_REQUEST['user_email'];
$user_name = $_REQUEST['user_name'];
//Check if username or email already exists
$check_username = "SELECT * FROM wp_users WHERE user_login = '".$user_name."'";
$userNameResult = $wpdb->get_results($check_username, OBJECT);
$check_useremail = "SELECT * FROM wp_users WHERE user_email = '".$user_email."'";
$userEmailResult = $wpdb->get_results($check_useremail, OBJECT);
if (count($userNameResult) != 0) {
echo "Username already taken";
die();
} else if(count($userEmailResult) != 0){
echo "Email already exists";
die();
} else{
$url = 'https://api.getresponse.com/v3/transactional-emails';
$params = array(
'fromFieldId' => '[email protected]',
'subject' => 'subject',
'content' => 'Message',
'to' => '[email protected]',
);
$curl = curl_init($url);
// Set the CURLOPT_RETURNTRANSFER option to true
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Set the CURLOPT_POST option to true for POST request
curl_setopt($curl, CURLOPT_POST, true);
// Set the request data as JSON using json_encode function
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));
// Set custom headers for X-Auth-Token, needed for Getresponse API
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'X-Auth-Token: api-key XXXX',
'Content-Type: application/json'
]);
// Execute cURL request with all previous settings
ob_start();
curl_exec($curl);
// close the connection, release resources used
curl_close($curl);
ob_end_clean();
echo "Check your mail and enter OTP";
die();
}
}
add_action('wp_ajax_nopriv_user_register_ajax', 'user_register_ajax');
add_action('wp_ajax_user_register_ajax', 'user_register_ajax');
If the user is not registered on the site he should get an email from getResponse mailing system with an OTP which the user will enter on the site and then he will get registered. Currently I’ve entered my email in the receiver’s email for testing purpose.
I’m stuck in the mailing part.
I had this code from Send mail using send grid api key and Pass Email and Name to GetResponse via API
I want to send an email from getResponse mailing system.
But so far this is all I got and can’t see the mistake in my code can anyone help me.