Created
January 5, 2024 01:38
-
-
Save AnadarProSvcs/3ddd8039c2c1ccd268ac19c4fcb7da42 to your computer and use it in GitHub Desktop.
Add a user to the MailerLite email provider. This currently only adds, using the PHP SDK had issues when running in an older version of PHP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add_subscriber_to_mailerlite($email, $name) { | |
$apiKey = 'YOUR_MAILERLITE_API_KEY'; // Replace with your MailerLite API Key | |
$groupId = 'YOUR_GROUP_ID'; // Replace with your MailerLite Group ID if necessary | |
$url = 'https://api.mailerlite.com/api/v2/subscribers'; | |
$data = array( | |
'email' => $email, | |
'name' => $name, | |
'groups' => array($groupId) | |
); | |
$options = array( | |
'http' => array( | |
'header' => "Content-type: application/json\r\nX-MailerLite-ApiKey: $apiKey\r\n", | |
'method' => 'POST', | |
'content' => json_encode($data), | |
), | |
); | |
$context = stream_context_create($options); | |
$result = file_get_contents($url, false, $context); | |
if ($result === FALSE) { /* Handle error */ } | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment