Skip to content

Instantly share code, notes, and snippets.

@jamescridland
Last active January 20, 2025 00:27
Show Gist options
  • Save jamescridland/5dfb9cda46c976c0f89ff9951acaf329 to your computer and use it in GitHub Desktop.
Save jamescridland/5dfb9cda46c976c0f89ff9951acaf329 to your computer and use it in GitHub Desktop.
Quick PHP function to check if this email is subscribed in Sendy
<?php
// A quick PHP function to check if a user is subscribed to your newsletter in Sendy.
// You need a Sendy API key; the list ID for your newsletter; and obviously your Sendy installation address.
// To use this
if (check_if_subscribed("[email protected]")=="Subscribed") {
echo "Yay!";
} else {
echo "Boo!";
}
function check_if_subscribed($email) {
GLOBAL $config;
$data = array('api_key' => $config['sendy-apikey'], 'email' => $email, 'list_id' => $config['sendy-listid']);
$yoursendyinstallation = "https://sendy.example.com";
$handle = curl_init($yoursendyinstallation.'/api/subscribers/subscription-status.php');
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($handle);
curl_close($handle);
return($result); // this returns "Subscribed" if the email address is subscribed.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment