无法将Laravel连接到MailChimp(laravel 5.4) [英] Unable To Connect Laravel to MailChimp (laravel 5.4)
问题描述
我必须在.env
文件中定义列表ID和MailChimp API密钥.我确定即使我没有收到任何错误,但都没问题,但是我没有在我安装的列表中插入 https://github.com/spatie/laravel-newsletter ( spatie/laravel-newsletter )软件包.
I have to define List ID and MailChimp API Key in my .env
file. I'm sure both are fine even I am not getting any error but email in not inserting in my List I installed https://github.com/spatie/laravel-newsletter (spatie/laravel-newsletter) Package.
这是我的方法
public function subscribe(Request $request)
{
$email = request('email');
Newsletter::subscribe($email);
Session::flash('subscribed', 'Successfully subscribed.');
return redirect()->back();
}
然后我检查Newsletter.php
它是
public function subscribe($email, $mergeFields = [], $listName = '', $options = [])
{
$list = $this->lists->findByName($listName);
$options = $this->getSubscriptionOptions($email, $mergeFields, $options);
$response = $this->mailChimp->post("lists/{$list->getId()}/members", $options);
if (! $this->lastActionSucceeded()) {
return false;
}
return $response;
}
我打印选项变量,它以以下形式返回输出
I print options variable it returns output as
array:3 [▼
"email_address" => "bluemoon@gmail.com"
"status" => "subscribed"
"email_type" => "html"
]
然后我在变量 $ response下打印,它返回false .请帮助解决此问题.
Then I print below variable $response it returns false Please Help whats wrong with this.
预先感谢
推荐答案
不确定这将直接解决您的问题,但是您需要在终端中运行以下命令:
Not sure this will directly resolve your issue, but you need to run the following command in your terminal:
php artisan vendor:publish --provider="Spatie\Newsletter\NewsletterServiceProvider"
这将在config
目录中创建一个laravel-newsletter.php
,这是您的列表ID和MailChimp API密钥应存放的位置.
This creates a laravel-newsletter.php
in the config
directory, that's where your List ID and MailChimp API key should go.
PS:该软件包似乎与env
有关,请不要使用它,只需输入您的密钥作为字符串即可.
PS: the package seems to have an issue with env
so don't use it, just enter your keys as strings.
这篇关于无法将Laravel连接到MailChimp(laravel 5.4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!