Hi.
I'm new to SELECT queries in SQL in the Moodle environment.
How do I write a code that will retrieve a Moodle user's email address and name from the mdl_user table, given the user's id?
So far all I have, which works, is the below code that will send an email message to myself. I hardcoded my own email address
in blue text. What I need to do is to email a message to any user, given his or her user id.
require_once('config.php');
$CFG->smtphosts = '';
echo '<pre>' . "\n";
$mail =& get_mailer();
$mail->From = $USER->email;
$mail->AddAddress('kamboonseng@gmail.com', 'Someone');
$mail->Subject = "A new message for you from ".$USER->firstname." ".$USER->lastname." ".$course->shortname;
$mail->IsHTML(false);
$mail->Body = "\nMessage:\n".$TheMainMessage;
if ($mail->Send()) {
echo 'Mail sent';
echo '</pre>';
} else {
echo('ERROR: '. $mail->ErrorInfo);
echo '</pre>';
}
Any help would be greatly appreciated.
Frankie Kam
Malaysia