mailjet / mailjet-apiv3-php

[API v3] Mailjet PHP Wrapper
http://dev.mailjet.com
MIT License
263 stars 86 forks source link

CURL Error 7 #214

Closed k3yma closed 3 years ago

k3yma commented 3 years ago

Have set up an simple test page on my NGINX server with PHP-FPM, however I am getting this in the PHP-FPM log:

[02-Dec-2020 18:56:57 UTC] PHP Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 7: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.mailjet.com/v3.1/send in /usr/share/nginx/html/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:210 Stack trace:

0 /usr/share/nginx/html/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(158): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)

1 /usr/share/nginx/html/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(110): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))

2 /usr/share/nginx/html/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php(47): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))

3 /usr/share/nginx/html/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(28): GuzzleHttp\Handler\CurlHandl in /usr/share/nginx/html/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 210

However I am able to use curl from the command line and send through the API fine. So it seems something isn't working quite right in the PHP side of things.

uavn commented 3 years ago

@johnkeymer This looks like configuration issue, or some firewall restrictions, if you use CentOS can you try to disable SELinux and try again?

Or create a clean php file with the following content:

<?php
$key = 'PU_YOUR_KEY_HERE';
$secret = 'PUT_YOU_SECRET_HERE';
$to = $from = 'PUT@YOUREMAIL.HERE';

$mj = new \Mailjet\Client($key, $secret, true, ['version' => 'v3.1']);
$body = [
    'Messages' => [
        [
            'From' => [
                'Email' => $from,
                'Name' => "Test"
            ],
            'To' => [
                [
                    'Email' => $to,
                    'Name' => "Test 1"
                ]
            ],
            'Subject' => "Subject Test",
            'TextPart' => "Subject Test",
        ]
    ]
];

$response = $mj->post(\Mailjet\Resources::$Email, ['body' => $body]);
print_r($response);

put your keys and email instead of placeholders and run script from command line:

php index.php

and see if you'll get the same error

uavn commented 3 years ago

Closing due to inactivity, posted answer should help