We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5689
    • 289 Posts
    I’m working on my church’s website, and part of what we need is a basic subscription system for visitors to choose which of a few different publications (newsletter, sermons, etc) they’d like to subscribe to by email. I have a system set up in place to take care of subscribing users, but what’s left to be done is an easy way for the church staff to send out the newsletter and other subscriptions.

    What I would really like to do is have an email address set up (with a random string of characters for the name, like [email protected] so it wouldn’t be easily guessed). Our office coordinator would send the newsletter email, for example, to that address, and then I’d have a cron job that runs a PHP script to check the email account, parse the email, and send a slightly customized version to each subscriber.

    I’ve been reading a bit about MIME email and all of that, and it seems that it’s no easy task to reliably parse any email like I’d need to. I can’t count on the church staff to, say, only send plain text emails or anything, so this needs to mostly fool-proof.

    Is this viable, or should I just use MODx documents and a custom module and some snippets to let the church staff just type their message and send it from there? I already have a basic way to do it in MODx that I setup, but I just figure it’s one less thing to teach them if I can set it up where they just send an email to a certain address and my PHP handles the actual distribution of the email.

    I’ve seen a PEAR class or two for doing this, but I was kind of intimidated looking over it.

    Any articles about doing this kind of thing or recommendations would be greatly appreciated. Thanks!
      I'm learning more about MODx all the time and loving it.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Piece of cake; just need the right tools! cool

      http://www.sottwell.com/email-posting.html
        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
        • 5689
        • 289 Posts
        Thanks for the article, sottwell. smiley I’m just not sure if that’s going to be fool-proof enough for a rather inexperienced church staff, though. You have it set up to check the first line for page title, second line for author, etc, and I don’t think I can count on our staff to remember to do something that specific.

        I’d really like to get the real subject of the email, and then get everything in the body. I also need to get attachments if there are any. From what I was reading yesterday, it’s kind of a pain to do all of that since emails can be formatted and encoded in so many different ways.
          I'm learning more about MODx all the time and loving it.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Well, you can get the subject, the body, and the sender’s email at the very least. That’s really all you need; get the user Id from the email. I just used the subject as the filter, you could use it for whatever you wanted.

          http://www.electrictoolbox.com/extract-attachments-email-php-imap/
          http://php.net/manual/en/ref.imap.php
            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
            • 5689
            • 289 Posts
            I’ve seen the imap function in the PHP documentation, but I’ll check out that other link and give it a try. Thanks again. smiley
              I'm learning more about MODx all the time and loving it.
              • 5689
              • 289 Posts
              I ended up going with this incredible class somebody created for parsing MIME email. http://www.phpclasses.org/browse/package/3169.html

              It does exactly what I need: it splits up the entire email into parts and stores it all in an array (which contains arrays and so on). It does all necessary decoding and whatever else, too.

              I now have a pretty decent setup where a staff member will be able to send an email to a certain address (it’d be something like [email protected] so that it can’t be guessed). My script (which runs by cron job every so many minutes) checks the account and sends any emails it finds to the entire mailing list, including any attachments. It also allows me to customize the email sent to each person to put in personalized unsubscribe links and so on.

              So, if anybody finds this topic and needs to do the same thing, I highly recommend giving that class a try. It’s a bit confusing to figure out at first, but there are some examples. It’s well worth figuring out how to use it.
                I'm learning more about MODx all the time and loving it.
                • 22435
                • 16 Posts
                Wow, that certainly is a complete class!

                For a quicker solution, sottwell’s looks a bit more approachable, though. Sottwell, did you implement your solution as a module, or as a free-standing file called in a resource?

                Thanks, both of you, for all the info.