Separate the two concerns into two different applications:
- The web application which provides the user interface
- A console script which sends the messages
The web application simply saves the messages to a database. Once the messages are saved (which is a fairly quick operation), the user can be redirected and can continue using the web application. Simply telling the user that the messages have been "queued" should be sufficient as an indicator of success at this time.
The console script simply reads from the database and sends the messages. With each one it would of course want to update that record in the database to indicate that it's been sent. (Or delete it entirely, depending on whether or not you want to keep a record of queued messages. Or update the record with some error information if the message fails so you can respond to failed attempts at a later time.)
Then just schedule the console script (likely with cron
or something similar) to run periodically. Every few minutes? Every hour? Every day? That's up to you. All it does when it runs is check the database for new queued messages and send them.