在Laravel 9中集成Sendinblue



我正在尝试将Sendinblue API集成到我的Laravel 9项目中。因此,我关注来自https://laravel.com/docs/9.x/mail#custom-运输

我已经安装了";symfony/ssendinblue mailer";包装";一个经过编辑的services.php文件,现在看起来像:

<?php
return [
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
'scheme' => 'https',
],
'postmark' => [
'token' => env('POSTMARK_TOKEN'),
],
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
'sendinblue' => [
'key' => 'My-code-is-here',
],

];

此外,我还通过文档中的以下代码修改了AppServiceProvider.php,因此该文件现在包含:

<?php
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateSupportFacadesMail;
use SymfonyComponentMailerBridgeSendinblueTransportSendinblueTransportFactory;
use SymfonyComponentMailerTransportDsn;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
//
}
public function boot()
{
Mail::extend('sendinblue', function () {
return (new SendinblueTransportFactory)->create(
new Dsn(
'sendinblue+api',
'default',
config('services.sendinblue.key')
)
);
});
}

}

当我尝试发送电子邮件时,我会收到以下错误:InvalidArgumentException:未定义Mailer[sendinblue]。在文件\vendor\laravel\framework\src\Illuminate\Mail\MailManager.php的第110行

我该如何解决那个问题?谢谢

可以使用的

Simplecurl。我在我的生产服务器中使用以下代码块,工作非常完美。

// ********** API EMAIL START **************
$toName = 'TO NAME';
$toEmail = 'TO EMAIL';
$fromName = 'FROM NAME';
$fromEmail = 'FROM EMAIL';
$subject = 'TEST SUBJECT';
$htmlMessage = '<p>Hello '.$toName.',</p><p>This is my first transactional email sent from Sendinblue.</p>';
$data = array(
"sender" => array(
"email" => $fromEmail,
"name" => $fromName         
),
"to" => array(
array(
"email" => $toEmail,
"name" => $toName 
)
), 
"subject" => $subject,
"htmlContent" => '<html><head></head><body><p>'.$htmlMessage.'</p></p></body></html>'
); 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.sendinblue.com/v3/smtp/email');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Api-Key: YOUR API KEY';
$headers[] = 'Content-Type: application/json';  
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
curl_close($ch);
/*
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
print_r($result);
*/
// *********  EMAIL API END **********************

相关内容

  • 没有找到相关文章

最新更新