Skip to content

Drupal RULES to autosubscribe new users

edited April 2013 in Troubleshooting

Hi there,

For those using Drupal. If you would like to autosubscribe users you can use the following in the Rules module.

Set up a new Rule > Event: After saving a new user account > Action: Execute custom PHP code

Copy the following code into the box:

$postdata = http_build_query(
array(
'name' => '[account:name]',
'email' => '[account:mail]',
'list' => 'your_list_key_from_sendy_backend',
'boolean' => 'true'
)
);
$opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
$context = stream_context_create($opts);
$result = file_get_contents('http://your_domain.com/subscribe', false, $context);

//CHECK RESULT
if($result) echo true;
else echo false;


Note:
YOU NEED TO ADD YOUR LIST KEY AND DOMAIN INTO THE CODE ABOVE!
You don't need any conditions in the Rule.
You don't need <?php ?> tags in the code
This does not allow the user to express their permission to get signed up to your list, so you might find that there are quite a few unsubscribes - in my case this will not happen, as I tend to personally know my users, but just be aware. A way around this might be to add an autoresponder after 0mins with an unsubscribe link in.


Idea from @Ben:
http://snipt.org/vhfha3

Comments

This discussion has been closed.