0

I'm trying to integrate the Sendinblue API in my Laravel 9 Project. Therefore I'm following the docs from https://laravel.com/docs/9.x/mail#custom-transports

I'v installed the "symfony/sendinblue-mailer" package" an edited the services.php file which now looks like:

<?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',
],

];

Moreover I have modified the AppServiceProvider.php by the following code from the docs, so that the file contains now:

<?php
 namespace App\Providers;
 use Illuminate\Support\ServiceProvider;
 use Illuminate\Support\Facades\Mail;
 use Symfony\Component\Mailer\Bridge\Sendinblue\Transport\SendinblueTransportFactory;
 use Symfony\Component\Mailer\Transport\Dsn;
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')
            )
        );
    });
}

}

When I try to send an email, I get the following error: InvalidArgumentException: Mailer [sendinblue] is not defined. in file \vendor\laravel\framework\src\Illuminate\Mail\MailManager.php on line 110

How can I solve that problem? Thanks!

gp_sflover
  • 3,460
  • 5
  • 38
  • 48
KTSB
  • 79
  • 4

1 Answers1

1

Simple curl you can use. I am using below code block in my production server and working perfectly.

// ********** 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 **********************

Nimesh
  • 104
  • 8