Skip to content
Advertisement

Sending an email using SwiftMailer (PHP) every X minutes

I can make my code work via sending emails whenever a client enters a specific page, the problem is that if the user/client reloads the page, a new email is sent, and that can lead to hundreds of mails being sent from my smtp server.

I am searching for a simple alternative which can only send a verification email every 5/10/15 minutes. Not when the user reloads the page.

Should I use javascript or a simple sleep on the function would work.

PD: Emails are being sent via $_SESSION variables on php.

Advertisement

Answer

You could either use a cron job for this (if your hosting environment allows you to define one), or keep track of when you’ve last send your emails yourself.

In the latter case, you could for example do:

JavaScript

For Cron & how to use it, see:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement