We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5683
    • 96 Posts
    This snippet sends e-mail messages to all the web users.

    It can be used in two ways:

    • providing a form that allows users to write and send a message;
    • allowing users to send the content of any page of your website as a message (in HTML format). In particular, if you insert a snippet call in your template, you can add a Send page as message link in every page. The link is displayed to a selected class of users only.

    # Newsletter v0.1 for MODx
    # Luca Allulli 2005
    #
    # Place the snippet in a document (let's call it the "main snippet document").
    # If you only want to send plain text messages manually, that's all.
    #
    # If you want to use the "Send page content" feature,
    # also add the following call in your page template:
    # [!Newsletter?sendId=<x>!]
    # where <x> is the id of the "main snippet document".
    
    
    #########################
    ## BEGIN CONFIGURATION ##
    #########################
    
    #General configuration
    $from='MySite Newsletter<[email protected]>'; //"From" field in sent emails
    $authorizedGroups=array("MyAuthWebGroup"); //Web user groups that can send page contents
    
    #Displayed messages
    $subjectLabel="Subject:";
    $messageLabel="Message:";
    $submitLabel="Send";
    $resetLabel="Reset";
    $messageSent="Your message has been sent to:";
    $sendPageMessage='<font color="#00FF00"><strong>Send this page as a NewsLetter</strong></font>';
    
    #########################
    ### END CONFIGURATION ###
    #########################
    
    
    #Initialization
    $output="";
    $pageid=$modx->documentIdentifier;
    
    if(isset($sendPageId)) {
    	
    	#Display link for sending content
    	
    	if($modx->isMemberOfWebGroup($authorizedGroups))
    		$output.='
    			<a href="index.php?id='.$sendPageId.'&sendId='.$pageid.'">
    	'.$sendPageMessage.'
    			</a>
    	';
    	
    } else {
    		
    	if((!isset($_POST['message']))&&(!isset($_GET['sendId']))) {
    		
    		#Display form
    		
    		$output .= "<div style='width:100%; text-align:center;'>";
    		$output .= "<form method='post' action='index.php'>";
    		$output .= "<input type='hidden' name='id' value='$pageid' />";
    		$output .= "<div>".$subjectLabel."</div><div><input name='subject' size='40' /></div>";
    		$output .= "<div>".$messageLabel."</div><div><text"."area rows='10' cols='50' name='message'></"."text"."area></div><br />";
    		$output .= "<div><input type='submit' name='submit' value='".$submitLabel."' />";
    		$output .= "  <input type='reset' name='reset' value='".$resetLabel."' /></div>";
    		$output .= "</form></div>";
    			
    	
    	} else {
    		
    		#Send messages
    		
    		if(isset($_GET['sendId'])) {
    			
    			$doc=$modx->getDocument($_GET['sendId'], 'pagetitle, content');
    			$subj=$doc['pagetitle'];
    			$msg='
    				<html>
    					<head><title>'.$subj.'</title></head>
    					<body>'.$doc['content'].'</body>
    				</html>
    			';
    			$contentType="text/html; charset=iso-8859-1";
    			
    		} else {
    			
    			$subj=$_POST['subject'];
    			$msg=$_POST['message'];
    			$contentType="text/plain";
    			
    		}
    		
    		$tbl = $modx->dbConfig['dbase'].".".$modx->dbConfig['table_prefix'];
    		
    		$sql = "SELECT * FROM ".$tbl."web_user_attributes;";
    		
    		$rs = $modx->dbQuery($sql);  # Execute the Query
    		$limit = $modx->recordCount($rs);  # Number of users found
    		
    		$output.="<p>".$messageSent."</p>";
    		$addr="";
    		$headers="MIME-Version: 1.0\r\n";
    		$headers.="Content-type: ".$contentType."\r\n";
    		$headers.="From: ".$from;
    		for ($i = 0; $i < $limit; $i++) {
    			$userattrib = $modx->fetchRow($rs);
    			$addr=$userattrib['email'];
    			$output.='<p>'.$addr.'</p>';
    	
    			mail($addr, $subj, $msg,	$headers);
    		}
    	
    	}
    	
    }
    	
    return $output;
    
      • 7455
      • 2,204 Posts
      Nice work but is it also posibele for people to subscribe to a newsletter?
      without needing to be a webuser?


      I am looking for somthing like that whith the opertunity to send a mail to all subscribers directly from a snipped or plugin.

      Great work Greets Dimmy
        follow me on twitter: @dimmy01
        • 32963
        • 1,732 Posts
        Very nice work Luca ,

        In TP3 you’ll be able to extend the NewsLetter snippet by adding features like backend News letter management and the ability to use a RichText editor for either the front-end or the backend.

        Keep up the good work. It’s really nice smiley I personally like the Send page as message feature
          xWisdom
          www.xwisdomhtml.com
          The fear of the Lord is the beginning of wisdom:
          MODx Co-Founder - Create and do more with less.
          • 5683
          • 96 Posts
          Thank you very much smiley

          Dimmy: I think webusers are the "natural" choice to send the newsletter to: it is possible to implement your concept of "newsletter subscriber" by creating a particular web user group "newsletter subscribers", and modifying the snippet so that it sends emails only to them. The problem is that users should have a way for subscribing as webusers belonging to a particular web user group; and I don’t know whether it is possible with the current API.

          Raymond: every new feature you add is exciting! I have another idea that is possible thanks to your plugin system: a plugin that automatically sends as a newsletter every "news", i.e. every saved child of a the "news" folder. I only have to figure out how to display a confirmation dialog box.

          Is it possible to parse the page content (i.e. to evaulate the snippets etc.), after retrieving it through $modx->getDocument?

            • 33337
            • 3,975 Posts
            Hi Commodore64 !

            Thank you for nice snippet !

            Best wishes and warm regards,

            zi
              Zaigham R - MODX Professional | Skype | Email | Twitter

              Digging the interwebs for #MODX gems and bringing it to you. modx.link
              • 32963
              • 1,732 Posts
              Quote from: Commodore64 at Jul 02, 2005, 12:45 AM

              Raymond: every new feature you add is exciting! I have another idea that is possible thanks to your plugin system: a plugin that automatically sends as a newsletter every "news", i.e. every saved child of a the "news" folder. I only have to figure out how to display a confirmation dialog box.

              Is it possible to parse the page content (i.e. to evaulate the snippets etc.), after retrieving it through $modx->getDocument?



              Sounds like a great idea smiley

              See the evalSnippets and mergeHTMLSnippetsContent, mergePlaceholderContent, mergeSettingsContent functions
                xWisdom
                www.xwisdomhtml.com
                The fear of the Lord is the beginning of wisdom:
                MODx Co-Founder - Create and do more with less.
                • 5683
                • 96 Posts
                Quote from: xwisdom at Jul 03, 2005, 03:12 AM

                See the evalSnippets and mergeHTMLSnippetsContent, mergePlaceholderContent, mergeSettingsContent functions

                Thank you! But I couldn’t find these functions neither in the Etomite nor in the MODx documentation... I guess I have to look at the source code, right?
                  • 33337
                  • 3,975 Posts
                  Hi Commodore !

                  Ofcourse ! you have to take look into source code of modx.

                  Regarding the functions, which xWisdom pointed out, please take a look at following attached text file.

                  Best wishes and warm regards, wink

                  zi
                    Zaigham R - MODX Professional | Skype | Email | Twitter

                    Digging the interwebs for #MODX gems and bringing it to you. modx.link
                    • 18397
                    • 3,250 Posts
                    Quote from: xwisdom at Jul 01, 2005, 09:59 PM

                    Very nice work Luca ,

                    In TP3 you’ll be able to extend the NewsLetter snippet by adding features like backend News letter management and the ability to use a RichText editor for either the front-end or the backend.

                    Keep up the good work. It’s really nice smiley I personally like the Send page as message feature

                    Luca, did anything ever come of this or of the web signup?
                      • 18397
                      • 3,250 Posts
                      Did anything ever come of this or of the web signup?