We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11712
    • 8 Posts
    As I was desperately searching how to use TV to build dynamically my mailinglist (see http://modxcms.com/forums/index.php/topic,33511.0.html), I’ve given up using a TV for this and reached my goal through a snippet.

    I manage my mailinglist through webgroups in Modx. So I need the &to parameter in eForm to be build dynamically with email addresses from a webgroup.

    I use an easy eForm call that contains a snippet call in the &to parameter:

    [!eForm? &formid=`feedbackForm` &to=`[[WebGroupMail? &webgroup=`Bureau`]]` &from=`[+email+]` &fromname=`[+name+]` &tpl=`eFormContact` &report=`eFormEmail` &thankyou=`eFormOKMerci` &vericode=`1` &subject=`Message de [+name+] ([+department+])` &language=`en`!] 


    The snippet WebGroupMail looks like that :

    <?php
    /**
         * WebGroupMail Snippet 1.0
         * @author Hamster Jovial
         * @version 1.0
         *
         *
         */
      // Variable verification
      // we need the webgroup name
    if (!isset($webgroup)) {return "nobody@nodomain"; }
    
       // Get the webgroup id
    $tblWebGroupNames = $modx->getFullTableName("webgroup_names");
    
    $requete1 = "SELECT `id`"
              ." FROM {$tblWebGroupNames}"
              ." WHERE `name` = \"$webgroup\"";
    $webgroupID = $modx->db->getValue( $modx->db->query( $requete1 ) );
    
      // the webgroupID will be used to query the members and their email addresses
      // First of all : define variables for both web_groups table and web_user_attributes
    $tblWebGroups = $modx->getFullTableName("web_groups");
    $tblWebUserAtt= $modx->getFullTableName("web_user_attributes");
    
    
      // Query
    $requete2 = "SELECT email"
              ." FROM {$tblWebUserAtt}"
              ." WHERE internalkey in (select webuser from {$tblWebGroups}  WHERE webgroup = {$webgroupID})";
    $sql = $modx->db->query( $requete2 ); 
    
      // Array resulting
    $col = $modx->db->getColumn( 'email', $sql );
    
    for( $i = 0; $i < count( $col ); $i++ ) 
    {
     if (isset($listadress))
     { $listadress.= ",".$col[$i]; }
    else
     { $listadress = $col[$i]; }
    }
        return $listadress;
    ?>


    the return of the snippet looks like [email protected],[email protected],[email protected] etc...
    So adding/removing an email address only goes through webgroup management wink
    I hope it can be usefull for some of you wink

    Olivier
      • 20413
      • 2,877 Posts
      Thanks for sharing! cool
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 30223
        • 1,010 Posts
        You do realize that you have a privacy problem doing it this way in that everyone on your mailing list can see all the other email addresses don’t you?
          • 11712
          • 8 Posts
          Quote from: TobyL at Mar 01, 2009, 11:39 PM

          You do realize that you have a privacy problem doing it this way in that everyone on your mailing list can see all the other email addresses don’t you?

          Yes I do, as my website is made for a sports team, it’s not a problem for me. But I realize it’s a KO criteria for larger internet communities. In that case I would have used the &bcc parameter wink