SendinBlue,guzzle:连接被拒绝
我正在开发一个项目,需要向客户发送交易电子邮件。
发送请求时出现以下错误。我使用SendinBlue V3 SDK。
Exception when calling TransactionalEmailsApi->sendTransacEmail: Connection refused for URI
https://api.sendinblue.com/v3/smtp/email
我的方法代码:
$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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否使用 Guzzle 正确配置了 https 客户端?
如果未连接,则可以检查是否引发任何其他异常。您可以在 Guzzle 文档中详细了解它们:https://docs。 guzzlephp.org/en/stable/quickstart.html#exceptions
在您的情况下,它是一个
ConnectException
。尝试获取更多相关信息。
为什么通常会抛出
ConnectException
?当无法连接时。
什么时候无法连接?当您没有使用正确的端点 url 时,还没有将 HTTP 客户端配置为使用 HTTPS 协议,也没有根据您在官方文档中找到的规格使用端点。
您也可以查看官方教程: https://developers.sendinblue.com/ docs/send-a-transactional-email
您也可以使用 github.com sendinblue 官方存储库,并详细描述了 php api :https://github.com/sendinblue/APIv3-php-library
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
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
文件说:
中继访问已被拒绝
身份验证可能已失败:检查您的 API 密钥,
另请确保您的 587 端口已打开。
运行 php artisan cache:clear 和 php artisan config:clear
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
andphp artisan config:clear