E-mail nofication of Course enrollment

E-mail nofication of Course enrollment

by Joseph Spilatore -
Number of replies: 4

My organiztion is using moodle to support some if its traditional standup training. When a student registers for a classes a supervisor needs to be notified. That being said, I am trying to create an automatic notification e-mail that gets sent when a student enrolls in a class. It should be said at this point that I am a relative newbie to PHP but I understand the major principals and codes

I have already created a field in the user_table for the superviosrs e-mail address. I was also able to create strings for the supemail, supname , supsubject and content in the moodle.php file.

I used the e-mail code from the changepassword.php file as a template and changed the string names.I have added the following lines of code to the enrol.php file after the enrollment key is found to be true.

email_to_user($supemail, $subject, $message)
    $a->email = get_string("supemail"),
    $subject = get_string("emailsupsuject"),
    $contents = get_string ("emailenrolltosup"),
    $from_header = get_string ("email");

I am currently recieving a Parse Error, unexpected 'T_VARIABLE' line 46 which is the 2nd line of code above.

Any thoughts as how this could be done or what the problem might be would be greatly appreciated!wide eyes

Average of ratings: -
In reply to Joseph Spilatore

Re: E-mail nofication of Course enrollment

by Chardelle Busch -
Picture of Core developers

Hi Joseph,

This coding could be very useful to others.  How is the "supervisor" identified in Moodle?  When you get it all worked out will you post the final results here? 

As for the error, try changing the   ,   at the end of your lines to a   ; 

In reply to Joseph Spilatore

Re: E-mail nofication of Course enrollment

by Teemu Sumi -
That is not the right way.

Check this out:

function email_to_user($user, $from, $subject, $messagetext, $messagehtml="", $attachment="", $attachname="") {
/// user - a user record as an object
/// from - a user record as an object
/// subject - plain text subject line of the email
/// messagetext - plain text version of the message
/// messagehtml - complete html version of the message (optional)
/// attachment - a file on the filesystem, relative to $CFG->dataroot
/// attachname - the name of the file (extension indicates MIME)

It's a function that sends mail.  $user, $from, $subject and $messagetext must be in your function call.

To get objects:

$someobject=get_record("user", "id", $someid);


Hope this helps.



Teemu
In reply to Teemu Sumi

Re: E-mail nofication of Course enrollment

by Joseph Spilatore -

Teemu,

Thank you so much for responding to my RFI. I added and customized the objects as you instructed, however I am now recieving unexpectecd T_IF on line 35.

My thinking is that if enrollment key is correct, an e-mail can be generated. Am I placing the code in the correct place in the enrol.php, If not where do I need to place and what to I need to add/subtract.

Thanksbig grin

 /// Check the submitted enrollment key if there is one

    if ($form = data_submitted()) {

        if ($form->password == $course->password) {
   function email_to_user($user, $subject, $messagetext)
 { $user=get_record("user", "id", "supemail", $supemail);
  $subject=get_record("user", "id",  $emailsupsubject);
  $messagetext=get_record("user", "id",  $emailenrolltosup)
 
  
           
      if (isguest()) {
                add_to_log($course->id, "course", "guest", "view.php?id=$course->id", $_SERVER['REMOTE_ADDR']);

In reply to Joseph Spilatore

Re: E-mail nofication of Course enrollment

by Teemu Sumi -
Your function call should be like this:

$user=get_record("user", "id", $USER->id);
$from=get_record("user", "id", 1);
$subject=get_string("emailsupsubject");
$messagetext=get_string("emailenrolltosup");
email_to_user($user, $from, $subject, $messagetext);

Try this one.


Teemu