I finally found the perfect solution: Cron Job
First of all, I created a database in which I save the βtaskβ to be completed
CREATE TABLE IF NOT EXISTS `cron_jobs_new_event` ( `cron_job_id` int(32) NOT NULL AUTO_INCREMENT, `event_id` int(32) NOT NULL, `user_id` int(32) NOT NULL, `notify` int(32) NOT NULL, `executed` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`cron_job_id`), KEY `event_id` (`event_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
I use hostgator, so I set up a cron job every 15 minutes: 
cron.php just call the method from my class Notification
<?php require 'core/init.php'; $notification = new Notification(); $notification->notifiedFollowers();
and this is my method that does magic (at least for me ;-)
public function notifiedFollowers(){ $query = $this->_db->prepare("SELECT user_id FROM cron_jobs_new_event WHERE executed = '0' AND notify = '1'"); $query->execute(); while($row = $query->fetch(PDO::FETCH_OBJ)) { $userCreator = $row->user_id; $q = $this->_db->prepare("SELECT * FROM followers WHERE user_id = ?"); $q->bindParam(1, $userCreator, PDO::PARAM_INT); $q->execute(); while($followers = $q->fetch(PDO::FETCH_OBJ)) { $type='try'; $creator = new User($followers->user_id); $creatorName = $creator->data()->name; $userFollower = new User($followers->followers_id); $mail = new PHPMailer(); $template = New MailFactory(); $mail->IsSMTP(); $mail->Host = "my host"; $mail->SMTPAuth = true; $mail->Username = "my username"; $mail->Password = "myPassword"; $mail->IsHTML(true); $mail->From = 'ev'; $mail->FromName = 'Events Team'; $mail->AddAddress($userFollower->data()->username); $mail->Subject = 'Somebody add a new event!'; $mail->Body = $template->notifiedFollowersEmail($creatorName, $userFollower->data()->name, $type, $followers->event_id); if(!$mail->send()) { echo $mail->ErrorInfo; die(); } }
I hope this helps someone else
source share