Achraf Khouadja Achraf Khouadja - 1 year ago 88
PHP Question

Mailchimp Does not work on production [laravel on azure]

I deployed a small laravel app that subscribes a user to a mailchimp list.
it's very basic yet it does not work on production

NOTE: EVERYTHING is fine in Localhost env and a CONTACT FORM WORKS FINE(uses SMTP)





Newsletter::subscribe($request->email, [
'firstName' => 'test',
'lastName' => 'tessst',
'listName' => 'whishlist' ], 'subscribers');

return response()->json([
'status' => 'success',
'msg' => 'Subscribed successfully']);

laravel-newsletter Config file


return [

'apiKey' => env('MAILCHIMP_APIKEY'),

'defaultListName' => 'subscribers',

'lists' => [

'subscribers' => [

'id' => '5920168294',
'whishlist' => [

'id' => '8e553f3d39',

My i guess is that this has something to do with HTTPS (i fixed the issue by adding a file
and referencing it in php.ini )
if this is the issue how can i fix this on azure?

And sorry there is no error output since it returns success to the ajax call.(if how can i get the response from mailchimp to check the error?)

Thanks in advance.

Answer Source

Well i dont know what is the issue here.

but i managed to make this work when i got rid of the package i'm using which is spatie/laravel-newsletter and used CURL instead and API V3.

 $email = $request->email;
    $listid = env('MAILCHIMP_LIST_ID');
    $apikey =  env('MAILCHIMP_APIKEY');
    $server = substr($apikey, strpos($apikey, '-') + 1);
    $auth = base64_encode('user:' . $apikey);
    $data = array(
        'apikey'        => $apikey,
        'email_address' => $email,
        'status'        => 'subscribed',
        'merge_fields'  => array(
            'FNAME' => 'test1',
            'LNAME' => 'test2',

    $json_data = json_encode($data);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://'. $server.''. $listid .'/members/');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
        'Authorization: Basic ' . $auth));
    curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
    $result = curl_exec($ch);
    return $result;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download