Here’s a quick trick that can help filter out spam text messages on your iPhone. Start by opening Settings.
Then choose Messages.
Scroll down to Message Filtering. Slide Filter Unknown Senders to the On position. Messages from people who aren’t in your contacts won’t cause notifications and they’ll be sorted into a separate list.
If you want to see messages from unknown senders, you can click the Unknown Senders tab in your iMessage inbox.