Hi everyone!
I'm trying to build a module where a student can ask for a tutorship to a specific professor and both can receive an email which says the date, time and reason of the tutorship.
To do it, i'm trying to use the function email_to_user($receiver, $sender, $subject, $body), which is one of the functions provided by Moodle.
What i am seeing, is that you can call this function to send an email only to the logged user, and if you want, using admin as sender.
But my idea is to send this email to both, student and professor. My problem is that the professor is not logged in that moment, and this function needs to take the user object of this professor from the database to include it in.
My question is, it is possible to take the object of the professor from the database, put it into a variable and include it in this function, or this function can only send the email to the user who is logged? And, if it is possible, how i must to do the sentence to take the professor object from the database?
I hope you understand my question.
Thanks for your help in advance!
I provide my code to be more clear:
$subject = get_string('Reserve confirmation');
$admin = get_admin();
if (!empty($_REQUEST['reserve'])) {
echo 'saving...';
$sid = $USER->id;
$tid = $_POST['teacher'];
$dat = $_POST['date'];
$hour = $_POST['time'];
$mot = $_POST['motive'];
$type = $_POST['type'];
$body = get_string("\nReserve confirmed to: \n" .$dat. "\n\nMotive: \n" .$mot. "\n\nType: \n" .$type. "\n");
email_to_user($USER,$admin,$subject,$body); //Here user is the user logged
Note: Here, when I use $USER, it is not necessary to take the info of the student from database because Moodle take it by default.