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://uplann.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;
}
CodePudding user response:
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
CodePudding user response:
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