Hi i want to send an email as soon as record is inserted in moodle database table, following code is not working
if ($recs = $ti_form->get_data()) {
// Do something with the data, then redirect to a new page
$lastinsertid = $DB->insert_record('suggestions', $recs);
$toUser = '[email protected]';
$fromUser = 'ICAN';
$subject = 'New Suggestion Added';
$messageText = 'New Suggestion Added';
$sent = email_to_user($toUser, $fromUser, $subject, $messageText);
//mail($to, $subject, $message, $headers);
if($sent) {
print "Email successfully sent";
}else{
print "There was an error sending the mail";
}
redirect('suggestions.php');
}
Above code givers error message. What could be the reason? Any help much appreciated.
Thanks
If you look at the phpdoc header for the email_to_user() function, the first 2 parameters should be user objects rather than strings.
So for the to user
For the from user you could use the support user