Email Notification for each course enrollment

Re: Email Notification for each course enrollment

by Rocio Forero -
Number of replies: 4

I am using the same code but when registering the user it shows me the error "unexpected token a in json at position 0"

The moodle version is 3.1

In reply to Rocio Forero

Re: Email Notification for each course enrollment

by marisol castro -

The code works perfectly but how do you make the $courselink clickable in the email?  I have tried so many ways but I keep getting syntax errors.  Any ideas??

Here is the code I did to try making the link clickable.  There must be a period or quote missing somewhere.  Please help!

require_once($CFG->libdir.'/moodlelib.php');
global $CFG;

$courselink = $CFG->wwwroot . "/course/view.php?id=" . $course->id;
$url = $CFG->wwwroot . "/course/view.php?id=" . $course->id;
$body = "You have been enrolled to course"." ".$course->fullname."."<br/><br/>"."Please login to start your course."."<br/><br/>echo <a href =". $url ."></a><br/><br/>"."Thanks,"."<br/>Admin";
email_to_user($user,$USER,'Enrollment Notification','The text of the message',$body);
echo json_encode($outcome);

In reply to marisol castro

Re: Email Notification for each course enrollment

by Nidhi Tiwari -

Try this:

echo <a href =". $courselink ."></a>;

In reply to Nidhi Tiwari

Re: Email Notification for each course enrollment

by marisol castro -

That didn't work.  I still get a syntax error.  Am I missing a quote or comma or  semicolon somewhere?


require_once($CFG->libdir.'/moodlelib.php');
global $CFG;

$courselink = $CFG->wwwroot . "/course/view.php?id=" . $course->id;
$body = "You have been enrolled to course"." ".$course->fullname."."<br/><br/>"."Please login to start your course."."<br/><br/>echo<a href =".$courselink."></a><br/><br/>"."Thanks,"."<br/>Admin";
email_to_user($user,$USER,'Enrollment Notification','The text of the message',$body);
echo json_encode($outcome);

In reply to marisol castro

Re: Email Notification for each course enrollment

by Guido Hornig -
Picture of Plugin developers

try:

$body = "You have been enrolled to course. ".$course->fullname." <br/><br/> Please login to start your course. <br/><br/> <a href =\"$courselink\">click here to go to the course...</a><br/><br/>Thanks.<br/>Admin";

1)

In PHP $name will be substituted in double quotes.  Not in single quotes

$name ="Miller";

echo "Tom $name";

:> Tom Miller

echo 'Tom $name';

:> Tom $name

2)

all the HTML, like <br> is just string content like letters a...z

echo "<h1> text</h1>";

:>

text


but when you want to print a " (double quotes)  than you need a so called escape character before. the excape character is the backslash in PHP 

echo "\"";

:> "

echo "\";

Syntax error

echo ' this is a double quote " ' ;

:> this is a double quote "

(please rate me,  if it helps)

Guido

from lern.link