3

I am using the following laravel package for my newsletters:

laravel-newsletter.

I have the following code in my newsletterController.php:

public function index() {
    Newsletter::subscribe('rincewind@discworld.com', ['FNAME'=>'Goti', 'LNAME'=>'Loki'], 'test');
    return 'Ola !';
}

Now when i go to: /newsletter in my application i see Ola !, but when i open my mailchimp dashboard i see don't see rincewind@discworld.com added to the list of emails for the list test.

I also tried the following method of the mailchimp package:

return Newsletter::isSubscribed('codedevakagautam@gmail.com');

This email address already exists in the list test, i get the following error:

Call to undefined method Spatie\Newsletter\Newsletter::isSubscribed() 

What am i doing wrong ? Can somebody please guide me.

Alexander Solonik
  • 9,838
  • 18
  • 76
  • 174
  • 1
    Mailchimp by default requires opt ins to be confirmed. Have you checked to see if you've had an email from mailchimp (might even be in your spam dir). If that is the case, check out their api docs as you can disable this. Alternatively more info would be needed, your best bet is going to be to go through the package debugging out at different points to see where its failing. I doubt its a bug in the package however as it's a pretty widely used one. – Sk446 Jul 30 '17 at 16:04
  • 1
    @Rick Thanks for your insights :) the docs however don't mention any opt - ins http://kb.mailchimp.com/integrations/api-integrations/about-api-keys as required and i did't received a email. I will try debugging , not sure what u mean exactly by opt ins – Alexander Solonik Jul 30 '17 at 16:31
  • Looks like it changed in the last api update. http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/ - you need to set the ip_opt and timestamp_opt values, and then set status to subscribed. Have a search around for 'double opt in mailchimp' as it's been mentioned a few times on SO before. – Sk446 Jul 30 '17 at 21:02
  • I think you not done subscribe with rincewind@discworld.com – AddWeb Solution Pvt Ltd Jul 31 '17 at 07:29
  • Rick thanks for the heads up !! – Alexander Solonik Aug 01 '17 at 05:51
  • Did you have defined the list `test` in `laravel-newsletter.php`? And Did you install the package correctly? – Cong Chen Aug 09 '17 at 15:11
  • @KelvinC i have installed the package just as suggested on the website and also yes i have defined test in my `laravel-newsletter.php` , which is inside the config folder . – Alexander Solonik Aug 09 '17 at 19:41
  • @AlexanderSolonik Did you push your code to your github repository? I want to check the codes. – Cong Chen Aug 10 '17 at 08:53
  • @AlexanderSolonik did you check Newsletter::getLastError(); ??? – Meera Tank Aug 10 '17 at 11:02
  • Did you call `subscribe` and `isSubscribed` in same class? – Cong Chen Aug 13 '17 at 05:30

1 Answers1

2

Please, verify if you have added an entry to the providers array at your config/app.php

// config/app.php
'providers' => [
    ...
    Spatie\Newsletter\NewsletterServiceProvider::class,
    ...
];

And at aliases array on the same file

// config/app.php
'aliases' => [
    ..
    'Newsletter' => Spatie\Newsletter\NewsletterFacade::class,
];

Also, you need to import the package on your controller. By doing:

use Newsletter;

Be sure to import this way.

If you did all of the steps above, now you can try to use the method:

return Newsletter::isSubscribed('codedevakagautam@gmail.com');

And to subscribe users to a list, you need to send a 'status' parameter. The possible values for this field is:

  • subscribed
  • unsubscribed
  • cleaned
  • pending

See the docs here: http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/

If this does not work for you, you can have a look at this package: https://github.com/drewm/mailchimp-api