Hi everyone
I'm trying to send a message through the message api (as an email) but i get the following error:
"Coding problem: $PAGE->context was not set. You may have forgotten to
call require_login() or $PAGE->set_context(). The page may not
display correctly as a result
- line 490 of /lib/pagelib.php: call to debugging()
- line 817 of /lib/pagelib.php: call to moodle_page->magic_get_context()
- line 1420 of /lib/weblib.php: call to moodle_page->__get()
- line 5853 of /lib/moodlelib.php: call to format_string()
- line 94 of /message/output/email/message_output_email.php: call to email_to_user()
- line 142 of /lib/classes/message/manager.php: call to message_output_email->send_message()
- line 104 of /lib/classes/message/manager.php: call to core\message\manager::send_message_to_processors()
- line 251 of /lib/messagelib.php: call to core\message\manager::send_message()
- line 35 of /blocks/myblock/cert_view.php: call to message_send()"
here is my code:
"require(__DIR__ . '/vendor/autoload.php');
require_once('../../config.php');
require_once(__DIR__ . '/config.php');
global $BU_CFG;
use mikehaertl\wkhtmlto\Pdf;
// Check for all required variables.
$course_id = required_param('course_id', PARAM_RAW);
$user_id = required_param('user_id', PARAM_RAW);
$url = isset($_GET['url']);
require_login();
if ($url) {
// Build the message object
$message = new \core\message\message();
$message->name = 'message_name';
$message->component = 'myblock';
$message->userfrom = $BU_CFG->BOT_ID;
$message->userto = 490;
$message->subject = 'message subject';
$message->fullmessagehtml = 'my message html';
$message->smallmessage = 'my message small';
$result = message_send($message);
echo 'נשלחה בהצלחה!';
} else {..."
As you can see i have "require_login();" in my code so i don't really understand what is wrong...
Also i made sure the "$message->name" is the same name that i defined in the "messages.php" file.
Moodle version: 3.2.1