Replies: 0
I’ve wrapped the basic Twilio SMS sending method into a function in a must-use plugin. I’ve added a form in the admin screen to retrieve a list of users’ and their numbers and can successfully send ($_POST) a message to the user chosen.
function sendtext() {
// Account SID and Auth Token from Twilio
$message_body = $_POST['message_body'];
$receiver = $_POST['receiver'];
$my_number = get_option( 'twilio_number' );
$sid = get_option( 'twilio_account' );
$token = get_option( 'twilio_auth_token' );
$client = new Client($sid, $token);
$client->messages->create(
// the number you'd like to send the message to
$receiver,
array(
'from' => $my_number,
// the body of the text message you'd like to send
'body' => $message_body
)
);
}
THE PROBLEM is calling the same function from my registration screen (script), to which I’ve added fields for mobile number and country.
Just below the wp_mail() can to send the password change message, I’ve added a reference to the sendtext() function. I have separate numbers for Canada and the USA so I’ve attempted like below to route variables to the sendtext() object but each time I get an error that a message could not be sent because a “To: number” was not included. (But a look at the user profile shows that the number is saved.) $receiver is the “To:” of the error message.
$user_country = $user->country;
$receiver = $user->tel;
/* Send Text to new user*/
if ($user_country == 'CA'){
$my_number = get_option( 'twilio_number' );
$sid = get_option( 'twilio_account' );
$token = get_option( 'twilio_auth_token' );
}
if ($user_country == 'USA'){
$my_number = get_option( 'twilio_number_usa' );
$sid = get_option( 'twilio_account_usa' );
$token = get_option( 'twilio_auth_token' );
}
$my_number = $my_number;
$sid = $sid;
$token = $token;
$receiver = $receiver;
$message_body = $message;
if(!empty($message)){
sendtext();
}
I’d expect a notice that no message was added but not “no TO: number” since that’s from the user_meta and not a form.
Any help in the proper structuring would be more than appreciated.
Thanks.
-
This topic was modified 2 minutes ago by
starapple.