Based on https://support.apple.com/102606 and https://support.apple.com/122621 :
A code is sent first, automatically via the Internet (not as a SMS text message), to a trusted device which is some other Apple computer or Apple mobile device signed in with your account. If you have a trusted device running iOS 11 and later, OS X High Sierra and later, iPadOS 13 and later, or watchOS 6 and later, the verification code is displayed automatically on your trusted devices.
If you don’t have a trusted device handy, you can choose to have a verification code sent to a trusted phone number as a text message or phone call.
1. Select “Didn’t Get a Code?” or “Can’t get to your devices?” on the verification code screen.
2. Choose to have the code sent to a trusted phone number (select which one—you can have several).
3. You'll get a text message or phone call from Apple with your verification code. This text message might include an additional domain validation line. This line includes the @ symbol, the website name, and your code (for example: @icloud.com #123456 %apple.com).
4. Enter the code on your other device to complete sign in.
Once you have access to your account again It is a good idea to have more than one trusted number.
If you had set up a recovery contact, read https://support.apple.com/HT212515
If you still can’t receive verification codes, you can request account recovery to regain access to your account. Read about that here ➔ https://support.apple.com/102656#:~:text=If%20you%20can't%20reset%20your%20password,%20request%20account%20recovery . Account recovery might take a few days or longer, depending on the specific account information you can provide to verify your identity.
If you feel you need to contact Apple, refer to this page for Apple Support ➔
https://support.apple.com/choose-country-region
Select your country (if you do not see your country, also look for "other" in regions; e.g., "Other Africa"), then "Choose a product". Click the "show" item under each category for more selections. If you don't see one that handles your issue then keep experimenting with selections until you reach one that gets you a chat session or a telephone call and get the representative to redirect you.
Here are various special problem scenarios:
If you did not get a code on your telephone:
- Is your phone number listed at Settings > [name on top] > Sign in & Security > Two Factor Authentication ?
- Are you able to receive other SMS messages (green)?
- If you see “Verification codes cannot be sent to this phone number at this time. Please try again later,”:
1) Wait a few hours and try again. Maybe it really does mean not at this particular time. E.g. ➔ https://discussions.apple.com/thread/256202233
2) Use this link to check the status of Apple’s various services and servers ➔
https://www.apple.com/support/systemstatus/
3) Disable or possibly remove entirely any VPN you are using.
4) Try clicking on, “Cannot use this number?”
- From: https://discussions.apple.com/thread/255010051
Q: Suddenly not getting texts for two factor authentication on iPhone
A: Reset network settings:
Go to Settings > General > Transfer or Reset iPhone > Reset > Reset Network Settings