Skip to content

Instantly share code, notes, and snippets.

@marcosnakamine
Last active April 3, 2017 16:51
Show Gist options
  • Save marcosnakamine/3fe4d9412b67b4d2fcbbeba0609b2256 to your computer and use it in GitHub Desktop.
Save marcosnakamine/3fe4d9412b67b4d2fcbbeba0609b2256 to your computer and use it in GitHub Desktop.
Sendy - Add contact in newsletter list via ajax
<?php
//------------------- Edit here --------------------//
$sendy_url = 'http://url';
$list = 't'; // LIST ID
//------------------ /Edit here --------------------//
//--------------------------------------------------//
//POST variables
$name = $_POST['name'];
$email = $_POST['email'];
//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($sendy_url.'/subscribe', false, $context);
//--------------------------------------------------//
echo $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment