# 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;
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?
See the evalSnippets and mergeHTMLSnippetsContent, mergePlaceholderContent, mergeSettingsContent functions
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 I personally like the Send page as message feature