Unable To Connect Laravel to MailChimp (laravel 5.4)

删除回忆录丶 提交于 2019-12-01 13:21:47

问题


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


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!