awesomemotive / WP-Mail-SMTP

The most popular WordPress SMTP and PHP Mailer plugin. Trusted by over 3 million sites.
https://wordpress.org/plugins/wp-mail-smtp/
GNU General Public License v3.0
55 stars 34 forks source link

cURL error 28: Connection timed out after 10000 milliseconds #137

Closed qazwsdc closed 1 month ago

qazwsdc commented 1 month ago

Expected Behavior

send mail using Mailgun

Current Behavior

Mailer: Mailgun http_request_failed: ["cURL error 28: Connection timed out after 10000 milliseconds"]

I'm sure there's nothing wrong with the settings, this only happens occasionally and has become more frequent recently. I have tested this command: curl -k https://api.mailgun.net and it's fine

sixFingers commented 1 month ago

Hey @qazwsdc 👋

Sorry to hear about your struggles. This is surely not due to a misconfiguration on your end, and it's almost surely not caused by WP Mail SMTP itself — the fact that it happens occasionally points to either cURL itself, or the Mailgun API, or your server configuration.

Did you try:

curl -k https://api.mailgun.net/

on your local machine, or on your server? If it's the former, would you try the latter?

Also:

  1. What version of PHP are you running?
  2. Is cURL up to date on your server?
qazwsdc commented 1 month ago

hi, PHP is 8.1.7 and I have do this: apt update apt install curl it says the curl is the newest version

I have tried the curl -k api.mailgun.net on my server and it's fine

sixFingers commented 1 month ago

Thanks for your feedback.

It'd be nice to try hitting the Mailgun API from your terminal right after you experience the issue in WP Mail SMTP. That way, we'd know it's the API being slow, rather than the client talking to it. In other words, as soon as you get a timeout error in WP Mail SMTP, hop on your server and:

curl -k api.mailgun.net

or even

traceroute api.mailgun.net

Another useful test would be to run a local installation of WP Mail SMTP with Mailgun setup, and try sending from your local server when you get a timeout on your "real" server. The idea with these tests is to understand if the problem is your server, or Mailgun.

qazwsdc commented 1 month ago

curl -k api.mailgun.net it says curl: (7) Failed to connect to api.mailgun.net port 443: Connection timed out But when I tried the command again it worked......

Maybe I should use a proxy? How to use a proxy in WP Mail SMTP? Thanks!

sixFingers commented 1 month ago

@qazwsdc Thanks! It seems Mailgun is the culprit, in which case a proxy wouldn't help (since if Mailgun API doesn't reply, or does so too slowly, you'd still get timeouts when requesting it). Let's dig a bit deeper:

  1. Are you using a firewall (e.g. iptables or ufw)?
  2. Are you using a proxy already?
  3. Is your server configuration completely custom, or are you using a common configuration from your hosting provider (I ask this as it's easier to check if this is a known issue on your hosting provider)?
qazwsdc commented 1 month ago
  1. my server is debian. ufw is the default. I haven't changed it
  2. no
  3. my server is custom. I install php mysql and so on by myself

But this server has been running fine for a long time, the problem only appeared recently, and I didn't change any configuration. By the way I upgrade wordpress to 6.6 already

sixFingers commented 1 month ago

@qazwsdc I see! This just makes me think Mailgun has some sort of issue, as weird as that sounds (you're the only user reporting this issue right now). Let's dig deeper:

  1. Which version of cURL are you running?
  2. Could you check both cURL and UFW logs, and see if there's anything related?
  3. What's the value of default_socket_timeout in your php.ini file? Would you try raising it, and see if that makes any difference?
  4. What's your hosting provider?
  5. How often does the issue pop up?
qazwsdc commented 1 month ago

I upgrade wordpress to 6.6, Now,it says "The test email may have been sent, but its reachability should be improved." Domain name check results: cURL error 28: Connection timed out after 5000 milliseconds BUT, the email was actually sent successfully, Should I continue to solve it or just ignore it?

about your question:

  1. cURL Information => 7.64.0
  2. How to check the logs when sending a test email?
  3. is the default value 60
  4. Tencent Cloud in China
  5. Every time
qazwsdc commented 1 month ago

Just confirmed, there is still a chance of sending failure.

qazwsdc commented 1 month ago

@sixFingers Perhaps the network environment in China is unstable.How to use proxy in this WP-mail-SMTP?

capuderg commented 1 month ago

Hi @qazwsdc,

I think it might be an issue on your server and the default timeout times are getting reached quite often.

Please try to Increase the default cURL Timeouts:

Add this to your theme's functions.php or in a site-specific plugin:

function qazwsdc_increase_curl_timeout( $handle ) {
    curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 30 ); // 30 seconds
    curl_setopt( $handle, CURLOPT_TIMEOUT, 30 ); // 30 seconds
}
add_action( 'http_api_curl', 'qazwsdc_increase_curl_timeout' );

Let us know if this will resolve it.

qazwsdc commented 1 month ago

@capuderg hi, I have changed to bravo and everything is Ok.So it's mailgun problem.Thanks

capuderg commented 1 month ago

Thank you for letting us know!

With that information, I suspect that Mailgun might be blocking some of the requests from China.