0

I need to send like 4000+ emails but individual emails to each using. Doing a foreach takes forever and the page loads until it finish (What really end up doing is an error).

I need to send those emails the best way possible and just leave the job in the background and return a response while that is happening.

If I didn't explain myself correctly, let me know.

Thanks a lot!

dacastro4
  • 363
  • 6
  • 17
  • 1
    [Have you looked into a Queue Job](https://laravel.com/docs/5.3/queues)? – maiorano84 Jan 07 '17 at 03:15
  • http://stackoverflow.com/questions/4626860/how-can-i-run-a-php-script-in-the-background-after-a-form-is-submitted –  Jan 07 '17 at 03:17
  • be super careful sending that much email, depending on on what email server and its set up this is a great way to get black listed. –  Jan 07 '17 at 03:18
  • 1
    @nogad That answer is over 6 years old. `shell_exec` is completely unnecessary in this case. Queues are a *much* more elegant solution, and fall within the capabilities of the framework. – maiorano84 Jan 07 '17 at 03:21
  • well it is how i still do it, but i dont use any framworks –  Jan 07 '17 at 03:40
  • @maiorano84 Thanks for the response. But what about the foreach loop with 4000+ users? I think that mostly the issue. – dacastro4 Jan 07 '17 at 03:47
  • ..... Queues run in the background on the command line. Seriously, did you read what I linked you to? – maiorano84 Jan 07 '17 at 03:50
  • @maiorano84 is correct. Use Queue Jobs. They are amazing. – MMMTroy Jan 07 '17 at 03:58
  • 1
    I highly recommend using a third party service to handle that much emails without handling it by yourself. That even guarantees accurate desirability too. Look for the answer below. – Gayan Jan 07 '17 at 07:40

1 Answers1

1

If you are looking for the best way to sending emails, I would highly suggest using a third party service.

There are many email services that guarantees sending your emails accurately to receivers inbox. Emails we send from our own email services provided by hosting providers mostly wind up in receivers spam folder. And also queuing up that much emails is not a solution as it would also bring up the question of what would happen if queue service failed.

I recently worked with a useful service which is named sendgrid. It helped me send that much emails without that much trouble.

You only need to loop though your data to format recipient and email content. Then send that data to sendgrid and they handle the emails.

refer this for more info.

Gayan
  • 3,614
  • 1
  • 27
  • 34