/** * Generate coupon email to send. * * @param \stdClass $emailto * @param string $emailbody * @param bool $initiatedbycron * @return \moodle_phpmailer */ protected static final function generate_coupon_mail($emailto, $emailbody = false, $initiatedbycron = false) { global $CFG, $USER; require_once $CFG->libdir . '/phpmailer/moodle_phpmailer.php'; // Instantiate mailer. $phpmailer = new \moodle_phpmailer(); // Set email from. if ($initiatedbycron) { // Get supportuser. $supportuser = \core_user::get_support_user(); $phpmailer->FromName = fullname($supportuser); $phpmailer->From = $supportuser->email; } else { $phpmailer->FromName = fullname($USER); $phpmailer->From = $USER->email; } // Set email body. if ($emailbody !== false) { $phpmailer->Body = $emailbody; } else { $bodyparams = array('to_name' => fullname($USER), 'from_name' => fullname($USER)); $phpmailer->Body = get_string('coupon_mail_content', 'block_coupon', $bodyparams); } // Set last phpMailer params. $phpmailer->AltBody = strip_tags($phpmailer->Body); $phpmailer->Subject = get_string('coupon_mail_subject', 'block_coupon'); $phpmailer->IsHTML(true); // Might not have a name cause the coupon recipients aren't neccesarily Moodle users. $phpmailer->AddAddress($emailto); $phpmailer->AddReplyTo($phpmailer->From, $phpmailer->FromName); $phpmailer->AddCustomHeader("X-COUPON-Send: " . time()); return $phpmailer; }