PHP function to add subscriber to MailChimp API 3.0
<?php
$data = [
'email' => $email,
'status' => 'subscribed',
'firstname' => $fname,
'lastname' => $lname
];
function syncMailchimp($data) {
$apiKey = 'XXX';
$listId = 'XXX';
$memberId = md5(strtolower($data['email']));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId;
$json = json_encode([
'email_address' => $data['email'],
'status' => $data['status'], // "subscribed","unsubscribed","cleaned","pending"
'merge_fields' => [
'FNAME' => $data['firstname'],
'LNAME' => $data['lastname']
]
]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode;
}
syncMailchimp($data);
?>
Also in PHP:
- artisan migrate one table
- dynamic input field laravel-livewire
- DateTime() php
- enable php errors for file folder
- < Php echo date("m") . " "; ?> what is the output of this script?
- check if substring in string php
- does php reverse array function
- check if a string contains another string php
- Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize()
- +1 day in while php
- datetime 24 hour format php
- add google analytics to website laravel
- cache clear laravel command
- base encode64 php image
- config cache clear in laravel
- eliminate duplicate values from associative array phph
- Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.3.0". You are running 7.2.33.
- array_values() in php
- connect mongodb with php
- add day for date php
- create random password with refresh in php
- SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was t oo long; max key length is 767 bytes
- composer require laravel/ui not working laravel 7
- delete route method in laravel