Auto subscriber new users (specific roles) to SimpleNews in Drupal 6

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
opegasus's picture

Hey all,

I am using Simple News in a Drupal 6 install.
I would like to create an 'auto subscribe' feature for specific roles (at least one for now) so that when someone
subscribes to the site for role 'X' they will automatically be subscribed to the newsletter.

In searches I found a PHP module someone built but it looks like it would auto subscribe anyone (regardless of role)
to the newsletter, not so good.

aic_mailer.module

<?php
/**
* Implementation of hook_user().
<em>
</em>/
function aic_mailer_user($op, &$edit, &$account, $category = NULL) {
    global $user;
    switch ($op):
        case "login":
            aic_mailer_check_subscriptions($user);
            break;
        case "logout":
            aic_mailer_check_subscriptions($user);
            break;  
    endswitch;
}

function aic_mailer_check_subscriptions($user, $debug='false') {
    if($user && $user->uid > 0){
        /* Change this number to your newsletter's tid */
       
$newsletter = 13;
       
simplenews_subscribe_user($user->mail, $newsletter, $confirm = FALSE);
    }
}
?>

There will be a declaration on the sign up form letting people know they will be auto subscribed as a required
part of the registration process to appease Simple News' requirements and to avoid cries of foul and spam.

So is this a Views thingy? How would I pass the specific role's email into Simple News?

Thanks for any clues, where to look, start.

Comments

Rules

scottrouse's picture

I've not used the SimpleNews module, but it claims to have Rules support. Have you looked into that? Rules makes it easy to perform some action (subscribe user to a newsletter) when something else is true (user is of certain role).

Ah, never thought of that.

opegasus's picture

I will give it a go and let you know.

Thanks Scott.

Rules +1

laken's picture

I would also look at Rules, it's the first place to look when you want to make a custom 'if this happens, then do that' workflow.

You wrote 'when someone subscribes to the site for Role X' - how are you letting users pick their own roles on signup?

Mail Chimp to the rescue!

opegasus's picture

For now we decided to use Simple News to do an EnMasse newsletter for one or two sendings.

With Mail Chimp we can enforce subscriptions at signup. We can also select the roles to assign MailChimp to. Pretty slick. We will convert the site's news over to MailChimp right after we relaunch. Meaning we (or 'I') will import all the email addresses from the database into MailChimp when we switch over.

Right now I am setting up MailChimp for all new subscriptions to the site.

@Andy: roles are set up for different registrations. One group signs up to be a 'Personal Guide' and the other signs up to be a 'Traveler'.

Each context has it's own registration pages to go through and when registration is complete, each type is auto-assigned into their given role.

With MailChimp, one simply selects the role...done. One can select to force subscription upon registration. So much smoother than SimpleNews.

This way I avoid all the hacks and rules needed (so far) to get SimpleNews to function as desired on the site. Guessing ahead, I just get to make sure that targeted newsletters go specifically to their respective groups.

Thanks Guys...

Actions and Triggers is another option

jutulen's picture

A simple solution is to use Actions and Triggers. Set up an Action to subscribe users to a newsletter. Set up a Trigger to run this Action when a new user account is created.