简体   繁体   English

SendinBlue,guzzle:连接被拒绝

[英]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.我使用 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;
}

Did you configure correctly your https client with Guzzle?您是否使用 Guzzle 正确配置了您的 https 客户端? 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您在 Guzzle 文档中有大量它们的清单: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 .在您的情况下,它是一个ConnectException Try to get more information about it.尝试获取有关它的更多信息。

Why ConnectException are thrown usually?为什么通常会抛出ConnectException 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.当您没有使用正确的端点 url 时,没有将您的 HTTP 客户端配置为使用 HTTPS 协议,没有根据其规格使用端点,您可以在官方文档中找到。

You can look the official tutorial too: https://developers.sendinblue.com/docs/send-a-transactional-email你也可以看看官方教程: 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您也可以将 github.com sendinblue 官方存储库与 php api 一起使用,描述如下: https://github.com/sendinblue/APIv3-php-library

Document says: Relay access has been refused Authentication may have failed: check your API key,文档说:中继访问已被拒绝身份验证可能失败:检查您的 API 密钥,

Please also be sure that your 587 port is open.还请确保您的 587 端口已打开。

run php artisan cache:clear and php artisan config:clear运行php artisan cache:clearphp artisan config:clear

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM