MAILCHIMP_KEY=jdsalkdnaskndsnaj
)'mailchimp' => [
'key' => env('MAILCHIMP_KEY'),
],
bu şekilde yapınca config('services.mailchimp.key')
dediğimde key'i buradan alabilirim.
composer require mailchimp/marketing
Route::get('mailchimp', function() {
$mailchimp = new \MailchimpMarketing\ApiClient();
$mailchimp->setConfig([
'apiKey' => config('services.mailchimp.key'),
'server' => 'us88'
]);
$response = $mailchimp->ping->get();
ddd($response);
});
sonuçta "health_status": "Everything's Chimpy!"
diyorsa doğru yoldayız demektir :)
lists->getAllLists()
diyebilirim. - doc link .
Route::get('mailchimp', function() {
$mailchimp = new \MailchimpMarketing\ApiClient();
$mailchimp->setConfig([
'apiKey' => config('services.mailchimp.key'),
'server' => 'us88'
]);
$response = $mailchimp->lists->getAllLists();
ddd($response);
});
list->getList('list_id')
diyebilirim - doc linklists->getListMembersInfo('list_id')
- doc linkaddListMember
metodunu kullanabiliriz - doc link
$response = $mailchimp->lists->addListMember("431xcvb", [
"email_address" => "[email protected]",
"status" => "subscribed", // "subscribed", "unsubscribed", "cleaned", "pending", or "transactional"
]);
Böyle yapınca Mailchimp panelinden de kontrol edersek yeni memberı eklemiş olduğumuz görülür$response = $mailchimp->lists->addListMember("xyz123", [
"email_address" => "[email protected]",
"status" => "subscribed", // "subscribed", "unsubscribed", "cleaned", "pending", or "transactional"
"merge_fields" => [
"FNAME" => "Osman",
"LNAME" => "Deneme",
]
]);
merge_fields alanının hangi değerleri alabileceğini incelemek için docs api
<form method="post" action="{{ route('newsletter') }}">
@csrf
<input type="email">
<input type="submit" value="Kaydet">
</form>
request()->validate(['email' => 'required|email']);
$mailchimp = new \MailchimpMarketing\ApiClient();
$mailchimp->setConfig([
'apiKey' => config('services.mailchimp.key'),
'server' => 'us88'
]);
try {
$response = $mailchimp->lists->addListMember('de213', [
'email_address' => request('email'),
'status' => 'subscribed'
]);
} catch (\Exception $e) {
throw ValidationException::withMessages([
'email' => 'This email could not be added to our list',
]);
}
redirect('/')->with('success', 'Email saved');
@error('email')
{{ $message }}
@enderror