SendinBlue,guzzle:连接被拒绝

发布于 2025-01-11 19:17:42 字数 1071 浏览 2 评论 0原文

我正在开发一个项目,需要向客户发送交易电子邮件。

发送请求时出现以下错误。我使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

摘星┃星的人 2025-01-18 19:17:42

您是否使用 Guzzle 正确配置了 https 客户端?
如果未连接,则可以检查是否引发任何其他异常。您可以在 Guzzle 文档中详细了解它们:https://docs。 guzzlephp.org/en/stable/quickstart.html#exceptions

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

在您的情况下,它是一个 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

. \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

烈酒灼喉 2025-01-18 19:17:42

文件说:
中继访问已被拒绝
身份验证可能已失败:检查您的 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 and php artisan config:clear

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文