3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
27 * Email message processor - send a given message by email
29 * @author Luis Rodrigues
30 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
33 require_once($CFG->dirroot.'/message/output/lib.php');
35 class message_output_email extends message_output {
37 * Processes the message (sends by email).
38 * @param object $message the message to be sent
40 function send_message($message) {
43 $userto = $DB->get_record('user', array('id' => $message->useridto));
44 $userfrom = $DB->get_record('user', array('id' => $message->useridfrom));
46 //check user preference for where user wants email sent
47 $usertoemailaddress = get_user_preferences('message_processor_email_email', '', $message->useridto);
49 if ( !empty($usertoemailaddress)) {
50 $userto->email = $usertoemailaddress;
53 $emailtagline = get_string('emailtagline', 'message', $SITE->shortname);
54 if (!empty($message->fullmessage)) {
55 $message->fullmessage .= "\n\n---------------------------------------------------------------------\n".$emailtagline;
57 if (!empty($message->fullmessagehtml)) {
58 //$message->fullmessagehtml .= "<br /><br />---------------------------------------------------------------------<br />".$emailtagline;
61 $result = email_to_user($userto, $userfrom,
62 $message->subject, $message->fullmessage,
63 $message->fullmessagehtml);
65 return $result===true; //email_to_user() can return true, false or "emailstop"
66 //return true;//do we want to report an error if email sending fails?
70 * Creates necessary fields in the messaging config form.
71 * @param object $mform preferences form class
73 function config_form($preferences){
75 $string = get_string('email').': <input size="30" name="email_email" value="'.$preferences->email_email.'" />';
76 if (empty($preferences->email_email)) {
77 $string .= ' ('.get_string('default').': '.$USER->email.')';
83 * Parses the form submitted data and saves it into preferences array.
84 * @param object $mform preferences form class
85 * @param array $preferences preferences array
87 function process_form($form, &$preferences){
88 $preferences['message_processor_email_email'] = $form->email_email;
92 * Loads the config data from database to put on the form (initial load)
93 * @param array $preferences preferences array
94 * @param int $userid the user id
96 function load_data(&$preferences, $userid){
97 $preferences->email_email = get_user_preferences( 'message_processor_email_email', '', $userid);