Go to Settings->Messages->Send&Receive and make sure your iCloud email address is checked. Ask for another code and hopefully it works.
Thanks to the person on Apple forums for this suggestion.
Thanks to the person on Apple forums for this suggestion.