'How to determine the email to sms gateway address of any phone number when using sms code verification

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...



Solution 1:[1]

As I see it, you've got two potential solutions.

1) Send the email to each carrier's sms gateway. If they don't own the number, they'll reply with something like this:

Error: Invalid user address

Error message below:
550 - Requested action not taken: no such user here

Save the gateway that works, then repeat the process if it stops working. (they changed providers)

2) Use an SMS provider, like Twilio, or subscribe to a service to lookup the gateway.

Solution 2:[2]

Some solutions might be:

  1. Google's libphonenumber package (https://github.com/google/libphonenumber) that provides carrier lookup (https://github.com/google/libphonenumber#mapping-phone-numbers-to-original-carriers)

  2. Email each carrier gateway. The downside is that this produces a lot of rejected 550 messages, which might get you flagged as a spammer. You might be able to reduce the rejected messages by ranking the carriers based on popularity for that country. If a more popular carrier rejects the message, then move on to the next carrier in the list. However, this has flaws because not all carriers send back rejection messages, and the overall process is slow.

  3. Many carriers offer a "transfer my phone number" feature, which could be used to check for a carrier: https://www.att.com/wireless/transfer-your-number/, https://www.verizon.com/switch-to-verizon/, etc. Most carriers want customers to transfer, and when that's not possible it's usually because the customer is already on that carrier. This approach might also be used in combination with emailing the carrier gateways.

Solution 3:[3]

Add the following to your sketch. On my system it places the image in the Downloads folder.

function keyTyped() {
  if (key == 's') {
    saveCanvas('photo', 'png');
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 iCodeSometime
Solution 2
Solution 3