php Spatie Newsletter - Mailchimp驱动程序- subscribe()方法不更新订户列表

z2acfund  于 2023-04-19  发布在  PHP
关注(0)|答案(1)|浏览(71)

我使用Spatie Newsletter package和Mailchimp驱动程序来处理Laravel应用程序中的时事通讯订阅。然而,当我调用subscribe()方法时,订阅者没有被添加到Mailchimp上的相应列表中,并且我没有收到任何错误消息。
下面是我使用的代码:

use Spatie\Newsletter\Facades\Newsletter;  
//    
public function Subscribe(Request $request)
{
    
    try {
        $subscription =  Newsletter::subscribe("joh.doe@gmail.com", ['FNAME'=>'Rince', 'LNAME'=>'Wind']);
        return response()->json([
            'message' => 'Newsletter subscription updated successfully',
            'data' => $user,
            $subscription

        ]);
    } catch (\Exception $e) {
        Log::error('Error subscribing to newsletter: ' . $e->getMessage());
        return response()->json([
            'message' => 'An error occurred while subscribing to the newsletter',
        ]);
    }

    /*$user->is_newsletter_subscribed = true;
     $user->newsletter_subscription_updated_at = now();
    $user->save();*/

}

这是我的配置文件newsletter.php

<?php

返回[

/*
 * The driver to use to interact with MailChimp API.
 * You may use "log" or "null" to prevent calling the
 * API directly from your environment.
 */
'driver' => env('NEWSLETTER_DRIVER', Spatie\Newsletter\Drivers\MailChimpDriver::class),

/**
 * These arguments will be given to the driver.
 */
'driver_arguments' => [
    'api_key' => env('MAILCHIMP_APIKEY'),
    'endpoint' => env('MAILCHIMP_LIST_ID'),
],

/*
 * The list name to use when no list name is specified in a method.
 */

/*
 * This key is used to identify this list. It can be used
 * as the listName parameter provided in the various methods.
 *
 * You can set it to any string you want, and you can add
 * as many lists as you want.
 */
'lists' => [
    'subscribers' => [
        /*
         * When using the Mail coach driver, this should be Email list UUID
         * which is displayed in the Mail coach UI
         *
         * When using the MailChimp driver, this should be a MailChimp list id.
         * http://kb.mailchimp.com/lists/managing-subscribers/find-your-list-id.
         */
        'id' => env('MAILCHIMP_LIST_ID'),
    ],
],

/*
 * Whether to use SSL when connecting to the MailChimp API.
 * Set to false to disable SSL.
 */
'ssl' => false,

];
没有抛出异常,但是函数返回false,并且mailchimp中的受众列表没有更新。
我已经检查了Mailchimp API密钥和列表ID是否正确。我还尝试使用subscribeOrUpdate()方法,但它也不起作用。
什么可能导致这个问题,我如何调试它?任何帮助将不胜感激。

2wnc66cl

2wnc66cl1#

根据 Package 上的this PR
“我一步一步地运行代码,发现如果NEWSLETTER_ENDPOINT像文档中所说的那样设置为空字符串,则无法正确构建Mailchimp端点。解决方案是将该值设置为null。”
所以'endpoint' => env('NEWSLETTER_ENDPOINT', ''),变成了'endpoint' => env('NEWSLETTER_ENDPOINT', null),

相关问题