I have to define List ID and MailChimp API Key in my .env
file. I'm sure both are fine even I am not getting any error but email in not inserting in my List I installed https://github.com/spatie/laravel-newsletter (spatie/laravel-newsletter) Package.
Here is my method
public function subscribe(Request $request)
{
$email = request('email');
Newsletter::subscribe($email);
Session::flash('subscribed', 'Successfully subscribed.');
return redirect()->back();
}
Then I check subscribe Method in Newsletter.php
it is as
public function subscribe($email, $mergeFields = [], $listName = '', $options = [])
{
$list = $this->lists->findByName($listName);
$options = $this->getSubscriptionOptions($email, $mergeFields, $options);
$response = $this->mailChimp->post("lists/{$list->getId()}/members", $options);
if (! $this->lastActionSucceeded()) {
return false;
}
return $response;
}
I print options variable it returns output as
array:3 [▼
"email_address" => "bluemoon@gmail.com"
"status" => "subscribed"
"email_type" => "html"
]
Then I print below variable $response it returns false Please Help whats wrong with this.
Thanks In advance
Not sure this will directly resolve your issue, but you need to run the following command in your terminal:
php artisan vendor:publish --provider="Spatie\Newsletter\NewsletterServiceProvider"
This creates a laravel-newsletter.php
in the config
directory, that's where your List ID and MailChimp API key should go.
PS: the package seems to have an issue with env
so don't use it, just enter your keys as strings.
来源:https://stackoverflow.com/questions/44911181/unable-to-connect-laravel-to-mailchimp-laravel-5-4