+ Post New Thread
Results 1 to 9 of 9
Virtual Learning Platforms Thread, Moodle - Multiple Emails in Technical; We are using Moodle here and I have set up a couple of questionnaires. When a user completes these it ...
  1. #1

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242

    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

    TechMonkey's Avatar
    Join Date
    Dec 2005
    Location
    South East
    Posts
    3,316
    Thank Post
    226
    Thanked 426 Times in 309 Posts
    Rep Power
    171
    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

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    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

    Join Date
    Dec 2007
    Location
    Preston
    Posts
    369
    Thank Post
    14
    Thanked 86 Times in 79 Posts
    Rep Power
    31

    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

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    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

    Join Date
    Dec 2007
    Location
    Preston
    Posts
    369
    Thank Post
    14
    Thanked 86 Times in 79 Posts
    Rep Power
    31

  7. Thanks to secretlife from:

    Hightower (8th December 2009)

  8. #7

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    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

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    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

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    242
    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!



SHARE:
+ Post New Thread

Similar Threads

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

Thread Information

Users Browsing this Thread

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

Posting Permissions

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