Last active
December 18, 2015 17:49
-
-
Save codeboxr/5820819 to your computer and use it in GitHub Desktop.
Sending Customized User Registration Email Alert to Admin in Moodle step2 From My blog post: http://codeboxr.com/blogs/sending-customized-user-registration-email-alert-to-admin-in-moodle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Send email to specified user with confirmation text and activation link. | |
* | |
* @global object | |
* @param user $user A {@link $USER} object | |
* @return bool Returns true if mail was sent OK and false if there was an error. | |
*/ | |
//update by codeboxr | |
function send_confirmation_email($user) { | |
global $CFG; | |
$site = get_site(); | |
$supportuser = generate_email_supportuser(); | |
$data = new stdClass(); | |
$data->firstname = fullname($user); | |
$data->sitename = format_string($site->fullname); | |
$data->admin = generate_email_signoff(); | |
$subject = get_string('emailconfirmationsubject', '', format_string($site->fullname)); | |
$username = urlencode($user->username); | |
$username = str_replace('.', '%2E', $username); // prevent problems with trailing dots | |
$data->link = $CFG->wwwroot .'/login/confirm.php?data='. $user->secret .'/'. $username; | |
$message = get_string('emailconfirmation', '', $data); | |
$messagehtml = text_to_html(get_string('emailconfirmation', '', $data), false, false, true); | |
$dataadmin = new stdClass(); | |
$dataadmin->admindata = generate_email_signoff(); | |
$dataadmin->supportname = $dataadmin->admindata->supportname; | |
$dataadmin->firstname = $data->firstname; | |
$dataadmin->sitename = $data->sitename; | |
$messageadmin = get_string('emailconfirmationtoadmin', '', $dataadmin); | |
$messagehtmladmin = text_to_html(get_string('emailconfirmationtoadmin', '', $dataadmin), false, false, true); | |
$user->mailformat = 1; // Always send HTML version as well | |
//email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $attachment='', $attachname='', $usetrueaddress=true, $replyto='', $replytoname='', $wordwrapwidth=79) | |
//send email to admin | |
email_to_user($supportuser, $supportuser, $subject, $messageadmin, $messagehtmladmin); | |
//directly email rather than using the messaging system to ensure its not routed to a popup or jabber | |
return email_to_user($user, $supportuser, $subject, $message, $messagehtml); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment