Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

Ready to contribute?

Amazing! Sign our contributors' agreement and then join us on GitHub.

Update for critical security issue in PHPMailer included in release Vanilla 2.3.1

Export emails from database

GermontGermont New
edited November 12 in Vanilla 2.3 Help

Hello!

Is there an easy way to export the user emails for a monthly newsletter. The forum uses Vanilla 2.3.1
I am especially trying to avoid banned/disabled users, as many of them would mark the email as spam.

Thank you!

Best Answer

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator
    Accepted Answer

    With "disabled" you mean "deleted"? You can get the mails directly per SQL:

    SELECT Email
    FROM GDN_User
    WHERE Banned = 0
    AND Deleted = 0
    

    Or you can write a tiny little plugin which uses the query builder. It must create an endpoint and should look similar to that:

        public function pluginController_exportMails_create($sender) {
            $sender->permission('Garden.Community.Manage');
            $mails = Gdn::sql()
                ->select('Email')
                ->from('User')
                ->where([
                    'Deleted' => 0,
                    'Banned' => 0
                ])
                ->get()
                ->resultArray();
            print_r(array_column($mails, 'Email'));
        }
    
    Germont

Answers

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator
    Accepted Answer

    With "disabled" you mean "deleted"? You can get the mails directly per SQL:

    SELECT Email
    FROM GDN_User
    WHERE Banned = 0
    AND Deleted = 0
    

    Or you can write a tiny little plugin which uses the query builder. It must create an endpoint and should look similar to that:

        public function pluginController_exportMails_create($sender) {
            $sender->permission('Garden.Community.Manage');
            $mails = Gdn::sql()
                ->select('Email')
                ->from('User')
                ->where([
                    'Deleted' => 0,
                    'Banned' => 0
                ])
                ->get()
                ->resultArray();
            print_r(array_column($mails, 'Email'));
        }
    
    Germont
  • have you looked at the mailchimp plugin? you could use that as a guide

    https://github.com/vanillaforums-plugins/MailChimpIntegration

    grep is your friend.

  • GermontGermont New
    edited November 15

    The owner need it for his shop, there is already a newsletter with html pattern and everything.
    @R_J
    There are still emails with Awaiting mail confirmation.
    But I even removed automatically with Notepad++ the lines with spamshit words.
    Thank you for great support ;)

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Check if adding "AND Confirmed = 1" to the conditions in the sql clause will give you "final" results.

Sign In or Register to comment.