If it really won't allow you & you control your own mail server can you set up an alias that will forward to more than person?
We are using Moodle here and I have set up a couple of questionnaires. When a user completes these it needs to send an email to some email addresses.
I've seen the option to send an email in the advanced settings, which works great except I can't seem to get it to send to more than one email address.
Any ideas how to achieve this?
If it really won't allow you & you control your own mail server can you set up an alias that will forward to more than person?
Timely question : there's a patch for this only just been done
[#CONTRIB-1542] send questionnaire results to more than one e-mail address - Moodle Tracker
Stupid question secretlife, but I came across that on my travels and wasn't quite sure what to do with it - any ideas?
from moodledocs: Development:How to apply a patch - MoodleDocs
Hightower (08-12-2009)
I tried to apply this patch but it failed. I think it's because my locallib.php didn't match what it was expecting.
I tried sending to multiple emails again and nothing, but still sends fine to one. Any ideas? I'm going to have to get nitty with the code aren't I?
Never mind - I have coded my own solution for this (tweaked the questionnaire files/db to suit).
I will be posting my solution up to Moodle when I get a minute (give back to the community). I will post the link here when I do that, in case anyone stumbles on this thread in hope for a solution.
THanks,
Ok, here's the post I made on Moodle to contribute my code back. Simple enough, but hopefully it will help someone else should they need the same feature.
Thanks,
1) Open /mod/questionnaire/locallib.php for editing, and find the function 'response_send_email'.
2) Find the following code within the above function:
$mail->Sender = $CFG->noreplyaddress;
$mail->From = $CFG->noreplyaddress;
// un-comment & replace validemailaddress in next 2 lines for tests on localhost (noreply address not allowed on localhost? JR DEV)
// $mail->Sender = 'validemailaddress';
// $mail->From = 'validemailaddress';
$mail->FromName = $name;
$mail->Subject = $subject;
$mail->AddAddress($email);
$mail->WordWrap = 79; // set word wrap
$mail->IsHTML(true);
$mail->Encoding = "quoted-printable"; // Encoding to use
$mail->Body = $body;
$mail->AltBody = "\n$body\n";
3) Before the $mail->Sender line (first line in block above) add the following:
$emailaddresses = preg_split('/,|;/', $email);
foreach ($emailaddresses as $address) {
4) After the $mail->AltBody line (second line in block above) add the following:
}
5) Find the $mail->AddAddress($email); line (about the middle of the block above) and change it to $mail->AddAddress($address);
The full block should now look like this:
$emailaddresses = preg_split('/,|;/', $email);
foreach ($emailaddresses as $address) {
$mail->Sender = $CFG->noreplyaddress;
$mail->From = $CFG->noreplyaddress;
// un-comment & replace validemailaddress in next 2 lines for tests on localhost (noreply address not allowed on localhost? JR DEV)
// $mail->Sender = 'validemailaddress';
// $mail->From = 'validemailaddress';
$mail->FromName = $name;
$mail->Subject = $subject;
$mail->AddAddress($address);
$mail->WordWrap = 79; // set word wrap
$mail->IsHTML(true);
$mail->Encoding = "quoted-printable"; // Encoding to use
$mail->Body = $body;
$mail->AltBody = "\n$body\n";
}
By adding this code we are telling the function to split the email addresses into individual addresses, which may be seperated by any of these characters:
, | ;
The foreach loop then runs through each email address and sends an email to that address.
This function is now set to email multiple email addresses. However, there are a couple of more tweaks needed to finalise things.
6) The structure of the database is set to only store 50 characters for this setting. So if your email addresses exceed this they will be trimmed to 50 characters. I used PHPMYADMIN to change this setting. Go into the Moodle database, then select the mdl_questionnaire_survey table and edit it's structure. Change the email field from 50 to a more sensible number (like 200) and update.
7) Open /mod/questionnaire/settings_form.php for editing. We are going to edit the settings box so it is a bit bigger making it more comfortable to view when there are multiple email addresses held within it. Find the line that reads:
$mform->addElement('text', 'email', get_string('email', 'questionnaire'), array('size'=>'30'));
and change the 30 at the end to 60
$mform->addElement('text', 'email', get_string('email', 'questionnaire'), array('size'=>'60'));
That's about it - your questionnaire should now email multiple addresses (i.e. email1@email.com;email2@email.com;email3@email.com), your database should be able to store these multiple addresses with ease, and your settings (where you set the email addresses) should be large enough to view confortably.
Remember to comment your code so you know what you've changed. I also updated the help file for the email setting so I can quickly see in the future how it works with the new changes I've made.
I'm sorry for waffling on, just trying to make this as easy as possible for anybody who would like to implement it.
Hope you found this useful.
Thanks!
There are currently 1 users browsing this thread. (0 members and 1 guests)