I am using the yii2-mailchimp extension which can be found here (Sammaye/yii2-mailchimp)
I am wanting to subscribe a user however am unable to access the Mailchimp_Lists class as I need to use the subscribe function within it.
Below is my setup
<?php
namespace frontend\controllers;
use sammaye\mailchimp\Mailchimp;
use frontend\models\Newsletter;
use yii\helpers\Html;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use Yii;
class NewsletterController extends Controller{
public function actionNewslettersignup()
{
$model = new Newsletter();
// Using isset will make sure, you don't trigger a Notice (when the variable does not exist)
$email = isset($_POST['Newsletter']['email']) ? $_POST['Newsletter']['email'] : null;
// Make sure you are receiving an email address
if ($email && filter_var($email, FILTER_VALIDATE_EMAIL))
{
// Subscribe User to List
$api_key = "xxxxxxxxxxxx";
$list_id = "xxxxxx";
$mc = new Mailchimp(['apikey' => $api_key]);
$Mailchimp_Lists = new Mailchimp_Lists( $mc );
//just to test what was being outputted
var_dump($mc->lists->getList());
echo $api_key;
echo $list_id;
}
// Display an error message ?
else
{
// @todo
}
}
}