I am building a web application that where a user can create an account. While the user is creating his account, he provides his phone number and the application needs to verify the number by sending an sms verification code. I used the following code to send the sms.
<?php
if ( isset( $_REQUEST ) && !empty( $_REQUEST ) ) {
if (
isset( $_REQUEST['phoneNumber'], $_REQUEST['carrier'],
$_REQUEST['smsMessage'] ) &&
!empty( $_REQUEST['phoneNumber'] ) &&
!empty( $_REQUEST['carrier'] )
) {
$message = wordwrap( $_REQUEST['smsMessage'], 70 );
$to = $_REQUEST['phoneNumber'] . '@' . $_REQUEST['carrier'];
$result = @mail( $to, '', $message );
print 'Message was sent to ' . $to;
} else {
print 'Not all information was submitted.';
}
}
?>
The problem with the code is that the user need to provide his network carrier. And to prevent a situation where a user will not be able to create an account be he may not know his carrier email to sms address, I decided to determine the carrier address from the provided phone number and/or country.
I was not able to figure out how to determine the carrier from the user's phone number. can anyone help me to figure it out?
I know it's possible because Facebook is doing something similar. Please suggest something else instead of telling me that it is not possible...
how to determine the carrier from the user's phone number
You cannot really. You can try by the phone prefix but in some countries people can migrate their numbers to different operators which basically means you will not know what operator it really is in the end.