We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18397
    • 3,250 Posts
    My work on the NewsLetter suite is progressing nicely.

    I currently have the following running on a test server:

    A module that when run allows you to send a newsletter (email) to all of the webusers (a more advanced version than Luca’s) with support for html (with templates) and text emails.

    A plugin that gives you the option of sending the current document you are creating/editing as a newsletter. It renders a checkbox on each document edit/create page in the manager and when this checkbox is checked it sends that page out to all of the webusers.

    I plan to write a modification of NewsPublisher that adds the same checkbox as in the plugin (very easy because of below).

    All of the newsletter sending code is located in a single php script stored on the server so it will be easy to enhance and maintain without worrying about multiple copies of the same code!

    Now, I would like to ask several questions to the dev team as to how to proceed.

    1. Should each subscriber be a webuser or a row in a new table?
    2. If the answer to the above is db row then how should I structure the db so that one subscriber can be subscribed to multiple newsletters?
    3. Should each email be sent with the php mail function or some other way?
    4. Anything advise?

    Thanks,
    Mark
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      there should be an new table, newsletter_recipient, that only has two fields, one the ID of the document in question and the other the user ID of one of its designated recipients.

      So you would need a relatively complex query to select the name and email address of every user from the web_user_attributes table where web_user_attributes.internalKey = newsletter_recipient.recipient_id joined on newsletter_recipient.document_id = (the id of the document in question).

      And I would use the php mail() function, why not?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 32963
        • 1,732 Posts
        You might also want to check out phpmailer.php

        manager/includes/controls/class.phpmailer.php

        It support SMTP and php mail() options. It can also be used to send out file attachments. So you could (in theory) attach images inside an HTML document to the email when sending out html documents
          xWisdom
          www.xwisdomhtml.com
          The fear of the Lord is the beginning of wisdom:
          MODx Co-Founder - Create and do more with less.
          • 18397
          • 3,250 Posts
          Interesting Raymond. Is this the correct examples page?

          http://phpmailer.sourceforge.net/extending.html

          Also, I don’t think I made myself clear regarding webusers or new db table. I was asking which does everyone think would be better, email to all webusers in a group or email to subscribers (stored in a separate table)?

          Also, if I go the db route? What is the correct structure?

          id, name, email, format, active, newsletters?

          But how would I store multiple newsletters? Comma or pipe delimited?
            • 25663 MODX Staff
            • 12,272 Posts
            Tables, defintely.

            A table of subscribers
            A table of newsletters to which they can subscribe
            A linking table of subscriber IDs / newsletter IDs
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 18397
              • 3,250 Posts
              So, if I understand correctly,

              Table one would contain:
              id, name, email, format, active

              Table two would contain:
              id, name, description, template, active

              Table 3 would contain
              table1.id and table2.id
              for every subscription

              So if a subscriber subscribes to two newsletters, there would be two rows for the same person?

              Is there any way to do this with just 2 tables or is this the best way to handle 1,000’s of subscribers?


                • 18397
                • 3,250 Posts
                Also, what table type should these be? (I don’t normally write SQL CREATE statements!)
                  • 25663 MODX Staff
                  • 12,272 Posts
                  Yes, there would be two rows.

                  This also brings up a design decision about adding an active column to the Table 3, as it has an implication on CAN-SPAM legistation.

                  In table 1, email MUST be unique. It should also include a record of opt-in confirmation dates... ideally capturing a solid record of when they confirmed that they subscribed.

                  I might add another table that is just for recording opt-ins/opt-outs dates/times: subscriberID, newsletterID, sub. request date/time, confirm date/time, remove date/time. (How you handle removals is tricky as well... needs to be automated, but also needs to be not easy to "fake" removals.)  When they confirm (or request if you prefer) removal, delete the record from the active subscriptions table (table 3).

                  Then you get into email bounce handling, which is anoher topic entirely... That can also weigh in on getting blacklisted at places like AOL.

                  Just a couple of things to think about... wink
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 18397
                    • 3,250 Posts
                    Raymond, I implimented phpmailer class but am having the most annoying problem.

                    Whenever I send anything using it, the From does not show up correctly in a mail (or webmail) program. Everything else works fine.

                    I decided to just create a small test script based on this tutorial (I intentionally DID NOT use SMTP):

                    http://phpmailer.sourceforge.net/tutorial.html

                    This is the php script that resulted (the module that uses this script echo’s the sendback variable):

                    <?php
                    
                    $output = "";
                    
                    $class = $modx->config['base_path'].'manager/includes/controls/class.phpmailer.php';
                    require $class;
                    
                    		$mail = new PHPMailer();
                    		$mail->From     = "[email protected]";
                    		$mail->FromName = "List manager";
                    		$mail->Sender  = "[email protected]";
                    		$mail->Mailer   = "mail";
                    		$mail->AddAddress("[email protected]", "Mark Kaplan");
                    		$mail->Subject = "first mailing";
                    		$mail->Body = "hi ! \n\n this is First mailing I made myself with PHPMailer !";
                    		$mail->WordWrap = 50;
                    
                    		if(!$mail->Send())
                    		{
                    				$output .=  "Message was not sent";
                    				$output .=  "Mailer Error: " . $mail->ErrorInfo;
                    		}
                    		else
                    		{
                    		   $output .= "Message has been sent";
                    		}
                    
                    $sendback = $output;
                    ?>
                    
                    



                    FYI: This php mail function worked fine in the full version of the script [before I implimented phpmailer]:
                    mail($addr, $subj, $msg, "From: ".$from."\r\n"."X-Mailer: Content Manager - PHP/".phpversion(), "-f $from");
                    


                    Help!
                      • 32963
                      • 1,732 Posts
                      did u try using isMail()?
                        xWisdom
                        www.xwisdomhtml.com
                        The fear of the Lord is the beginning of wisdom:
                        MODx Co-Founder - Create and do more with less.