+ Reply to Thread
Results 1 to 9 of 9

Thread: Moodle - Multiple Emails

  Share/Bookmark
  1. #1

    Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation
    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    2,884
    Thank Post
    248
    Thanked 264 Times in 189 Posts
    Rep Power
    94

    Default Moodle - Multiple Emails

    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?

  2. #2

    Reputation Reputation Reputation Reputation Reputation Reputation Reputation

    Join Date
    Dec 2005
    Location
    East Sussex
    Posts
    1,753
    Thank Post
    54
    Thanked 92 Times in 65 Posts
    Rep Power
    36

    Default

    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?

  3. #3

    Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation
    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    2,884
    Thank Post
    248
    Thanked 264 Times in 189 Posts
    Rep Power
    94

    Default

    Quote Originally Posted by TechMonkey View Post
    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?
    I can do this - but I was hoping there'd be a solution in Moodle. Otherwise there'd be forwarders going all over the place.

  4. #4

    Reputation Reputation Reputation Reputation

    Join Date
    Dec 2007
    Location
    Preston
    Posts
    237
    Thank Post
    12
    Thanked 47 Times in 42 Posts
    Rep Power
    16

    Default patch

    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

  5. #5

    Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation
    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    2,884
    Thank Post
    248
    Thanked 264 Times in 189 Posts
    Rep Power
    94

    Default

    Stupid question secretlife, but I came across that on my travels and wasn't quite sure what to do with it - any ideas?

  6. #6

    Reputation Reputation Reputation Reputation

    Join Date
    Dec 2007
    Location
    Preston
    Posts
    237
    Thank Post
    12
    Thanked 47 Times in 42 Posts
    Rep Power
    16

  7. Thanks to secretlife from:

    Hightower (08-12-2009)

  8. #7

    Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation
    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    2,884
    Thank Post
    248
    Thanked 264 Times in 189 Posts
    Rep Power
    94

    Default

    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?

  9. #8

    Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation
    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    2,884
    Thank Post
    248
    Thanked 264 Times in 189 Posts
    Rep Power
    94

    Default

    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,

  10. #9

    Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation
    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    2,884
    Thank Post
    248
    Thanked 264 Times in 189 Posts
    Rep Power
    94

    Default

    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!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Moodle Emails
    By Mintsoft in forum Virtual Learning Platforms
    Replies: 8
    Last Post: 02-10-2009, 09:56 AM
  2. Bouncing emails
    By kearton in forum Internet Related/Filtering/Firewall
    Replies: 11
    Last Post: 23-09-2009, 01:42 PM
  3. Staff emails and VLE emails
    By e_g_r in forum Virtual Learning Platforms
    Replies: 2
    Last Post: 12-11-2008, 06:26 PM
  4. Blank Emails
    By plexer in forum ICT KS3 SATS Tests
    Replies: 2
    Last Post: 02-05-2006, 07:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts