Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SendinBlue, guzzle: Connection refused

I'm working on a project where I need to send transactional emails to my clients.

The following error appears when sending the request. I use SendinBlue V3 SDK.

Exception when calling TransactionalEmailsApi->sendTransacEmail: Connection refused for URI
https://api.sendinblue.com/v3/smtp/email

My method code:

$config = Configuration::getDefaultConfiguration()->setApiKey('api-key', 'secret');
$apiInstance = new TransactionalEmailsApi(
    new GuzzleHttp\Client([
        'base_uri' => 'https://[secret].online'
    ]),
    $config
);
$sendSmtpEmail = new SendSmtpEmail();
$sendSmtpEmail['to'] = [
    [
        'email' => $parameters['mail'],
        'name' => $parameters['user'],
    ]
];
$sendSmtpEmail['templateId'] = 3;
$sendSmtpEmail['params'] = [
    'FIRSTNAME' => $parameters['user'],
    'LASTNAME' => $parameters['verification_code'],
];

try {
    $result = $apiInstance->sendTransacEmail($sendSmtpEmail);
    print_r($result);
} catch (ConnectException $e) {
    echo 'Exception when calling TransactionalEmailsApi->sendTransacEmail: ', $e->getMessage(), PHP_EOL;
}
like image 248
peterhillie Avatar asked Nov 16 '25 09:11

peterhillie


2 Answers

Did you configure correctly your https client with Guzzle ? If not connecting, then you can check if any other exceptions are thrown. You have a great inventory of them in the Guzzle documentation : https://docs.guzzlephp.org/en/stable/quickstart.html#exceptions

. \RuntimeException
└── TransferException (implements GuzzleException)
    ├── ConnectException (implements NetworkExceptionInterface)
    └── RequestException
        ├── BadResponseException
        │   ├── ServerException
        │   └── ClientException
        └── TooManyRedirectsException

In your case, it is a ConnectException. Try to get more information about it.

Why ConnectException are thrown usually ? When you can not connect.

When you can not connect ? When you are not using correct endpoint url, have not configured your HTTP client to use HTTPS protocol, not using the endpoint accordingly to its specs you'll find inside official documentation.

You can look the official tutorial too : https://developers.sendinblue.com/docs/send-a-transactional-email

You can use the github.com sendinblue official repository too with the php api well described : https://github.com/sendinblue/APIv3-php-library

like image 118
BendaThierry.com Avatar answered Nov 19 '25 01:11

BendaThierry.com


Document says: Relay access has been refused Authentication may have failed: check your API key,

Please also be sure that your 587 port is open.

run php artisan cache:clear and php artisan config:clear

like image 35
gguney Avatar answered Nov 19 '25 00:11

gguney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!