If you go to Settings > Messages, you can filter out messages from unknown senders. However, this only prevents the notifications from showing up; they'll still be in the app under the "Unknown senders" tab.
FWIW, T-Mobile does allow you to block all SMS and MMS.