/** * Send an email to (a) specified user(s) * * @param string $templatename Name of the template as described in * the global $email array or overridden * in the mdl_email_template table * @param array $options array of options to pass into each email * @param array $loopoptions array of array of options to pass into * individual emails. This could for instance * be used to send emails to multiple users * send($tname, * array('course' =>1 ), * array(array('user' => 1),array('user' => 2),array('user' => 3)) * ) * @return bool if no $loopoptions where specified: * Returns true if mail was sent OK and false if there was an error * or in case $loopoptions were specified: * returns number of successes (ie. count of $loopoptions) * or if there was an error, those $loopoptions for which there was an error */ public static function send($templatename, $options = array(), $loopoptions = array()) { if (count($loopoptions)) { $results = array(); foreach ($loopoptions as $loptions) { $combinedoptions = array_merge($options, $loptions); $ok = false; try { $ok = self::send($templatename, $combinedoptions); } catch (Exception $e) { // Something to go here. } if (!$ok) { $results[] = $loptions; } } if (count($results)) { return $results; } else { return count($loopoptions); } } else { $emailtemplate = new self($templatename, $options); return $emailtemplate->queue_for_cron(); } }