0

I've just set up an installation of Sendy (http://sendy.co) - it uses Amazon's SES infrastructure to send out emails at really cheap rates.

It all works well and I'm trying to integrate it into Drupal Rules such that a new user is automatically added to an email list.

I've set up a new Rule: After saving a new user account > Execute custom PHP code

and then added this code:

$your_installation_url = 'http://my-site.com'; //The domain in question
$list = '1234'; //A string which relates to an email list

//POST variables
$names = '[account:name]';
$emails = '[account:mail]';
$name = $_POST['$names'];
$email = $_POST['$emails'];
$boolean = 'true';

//Check fields
if($name=='' || $email=='')
{
    echo 'Please fill in all fields.';
    exit;
}

//Subscribe
$postdata = http_build_query(
    array(
    'name' => $name,
    'email' => $email,
    'list' => $list,
    '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($your_installation_url.'/subscribe', false, $context);

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

This code (minus the Drupal Tokens) works perfectly as a standalone PHP file - however the above code in Rules fails to do anything.

I was hoping that someone might spot an obvious slip up here - perhaps the tokens are incorrect or incorrectly used. I'm trying to capture the newly created user's Username and email address and POST them to the $results URL.

Thanks in advance.

  • Could not relate to error in above code,however if subscribing to email list is you want you can send an ajax call to subscribing function and pass email address field only at the time of user registration. – Prerit Mohan Apr 28 '13 at 20:18
  • Thanks for taking the time to reply. I was wondering if you might be able to expand upon that a little. I don't really know what you mean. – njwrigley Apr 29 '13 at 7:13
  • Well what I meant was that you can tweak the user registration form and add fields saying that do you wish to receive updates via email. And then in your submit function you can pass the captured email to the amazon subscribe function with the help of an Ajax call and then submit the form. – Prerit Mohan Apr 29 '13 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.