3

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;
}
peterhillie
  • 107
  • 1
  • 13

2 Answers2

3

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

BendaThierry.com
  • 2,080
  • 1
  • 15
  • 17
  • I added [protocols https] to the guzzle client, still same error. – peterhillie Mar 04 '22 at 20:30
  • Issue is still there. I also added an extra curl support on tls.1.2 but even that didn't work. With postman it work with production server it doesn't, we have a normal lets encrypt ssl cert. – peterhillie Mar 04 '22 at 21:49
  • Ok. Which php extensions are enabled in your dev environment and not in your production environment ? Did you check the required php extensions/modules for using the sendmail PHP API v3 features in your production env ? ext/json, and others : are they enabled ? – BendaThierry.com Mar 05 '22 at 18:24
  • Did your install Guzzle on your production server ? Sometimes some people deploy only the webapplication, and forget to install/update/refresh some dependencies using composer, or the new versions of the dependencies have some breaking changes. – BendaThierry.com Mar 05 '22 at 18:29
  • If guzzle wasnt installed, you didnt got the exception – Pieter Dijkstra Mar 06 '22 at 19:09
  • @BendaThierry.com I don't use sendmail php. It is just a simple guzzle http request against sendinblue. How hard is it to solve this. The problem is still there. I also update composer so that is not the problem. Other things works perfectly. – peterhillie Mar 06 '22 at 19:44
  • @peterhillie It is not hard to solve that kind of problem. Compare your local php configuration with your production php config. Configure a third environment where you can run some integration testing with your pre-production code. When I have talked about "sendmail PHP API v3", it is your SendInBlue php code using the REST API and not the sendmail local program. – BendaThierry.com Mar 10 '22 at 10:22
1

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

gguney
  • 2,512
  • 1
  • 12
  • 26