Sid
Sid

Reputation: 5833

integrating mailchimp with laravel resulting an error

I am trying to make use of this package in order to push all the subscribed email to the mail chimp subscriber list. I have followed the instructions as provided but every time i try to subscribe an email, its giving me an error called

 ServiceRefusedSubscription in NewsletterList.php line 48:
API call to lists/subscribe failed: SSL certificate problem: unable to get local issuer certificate

I have set the MAILCHIMP_API_KEY and LIST_ID in my .env file and here is my controller where I am trying to achieve the result

public function postSubscribe(Request $request)
    {
       $v = validator::make($request->all(), [
           'email' => 'required|email|unique:subscriber'
       ]);

        if ($v->fails()){
            return redirect::back()
                ->withErrors($v->messages());
        } else {
               \Newsletter::subscribe(Input::get('email'));
                $sub = new Subscriber;
                $sub->email         = Input::get('email');
                $sub->subscribed    = 1;
                $sub->save();

            return redirect::back()
                ->with('messsage', 'Subscribed successfully');
        }
    }

Now I want this entered email to save in the list that I have created in mailchimp but I am getting the error that was mentioned above. What I am doing wrong? If anyone can help me please :)

Upvotes: 0

Views: 769

Answers (1)

Jeemusu
Jeemusu

Reputation: 10533

I am assuming this is on a local development server? The NewsletterList package uses cURL to integrate with the Mailchimp API. Mailchimp expects you to connect over SSL so the cURL requests will try to verify that your servers SSL certificate is authentic. If it can't validate your certificate, then you will see the error message you provided.

You could disable the SSL authentication in the Mailchimp API wrapper, but ideally you want to be using SSL.

One work around for your local environment is to download the cacert.pem from the cURL site and then add/update the following line in your php.ini.

curl.cainfo="D:path\to\your\cacert.pem"

Don't forget to restart Apache.

Upvotes: 1

Related Questions