Where do I customize the email sent when a new message is sent to a user?

Where do I customize the email sent when a new message is sent to a user?

by Sergio Tapia -
Number of replies: 4

Imagine two people enrolled in a course.

Person A messages Person B.

Person B is currently receiving an email telling them someone has messaged them. 

 

Where and how can I customize this email? I've searched high and low in the source code, but could not find anything concrete. Is there a template somewhere in there? Thanks for the help.

Average of ratings: -
In reply to Sergio Tapia

Re: Where do I customize the email sent when a new message is sent to a user?

by Dan Poltawski -
In /lang/, probably the message.php file, which you can customise using Language_customization.

If would usually git grep for the string to find out.
Average of ratings: Useful (1)
In reply to Dan Poltawski

Re: Where do I customize the email sent when a new message is sent to a user?

by Sergio Tapia -

Thank you, that helped a lot. I found this in the lang/en/message.php file:

$string['emailtagline'] = 'This is a copy of a message sent to you at "{$a->sitename}". Go to {$a->url} to reply.';

I can understand the concept that the link is being dynamically genereted by a script somewhere. The '{$a->url}' bit.

Where should I look for if I want to change the generated link? I want to append a certain url GET parameter into it. Thanks!

 

In reply to Sergio Tapia

Re: Where do I customize the email sent when a new message is sent to a user?

by Hubert Chathi -

Just use your favourite tool to search for where 'emailtagline' appears in the code, and that will tell you where it is used.  In the version of Moodle I have, it is in message/lib.php.

Average of ratings: Useful (1)
In reply to Sergio Tapia

Re: Where do I customize the email sent when a new message is sent to a user?

by Sergio Tapia -

Great, I managed to find the exact area in the source files I need to modify.

/messages/lib.php : line - 2042

This is how the default Moodle code looks like:

$s->url = $CFG->wwwroot.'/message/index.php?user='.$userto->id.'&id='.$userfrom->id;

 

Here is the change I have already made in order for the course name and link to show up in the message window when somebody clicks the link to the conversation.

# This is where we're going to change the URL that is sent along with the email when a new
# message is sent to a user.
$s->url = $CFG->wwwroot.'/message/index.php?user='.$userto->id.'&id='.$userfrom->id.'&courseId='.'2';

 

I've already worked out the details on how to wire this up. I just need to figure out how to provide the correct course ID value to the GET parameter listed there in the code above.

As my code stands, I've hard coded a static '2' value for courseId just to test it out, and it works fine.

Is there a way for me to find out the course the user was in previously and place that value there? I notice there's a CONTEXT_COURSE variable in the original code, but I'm not sure if this is what I need to use or even how to use it.

 

I really appreciate the help. Once I'm done I'll write a small tutorial as I'm sure I'm not the first or last one who needs this sort of functionality.