Advertisement
filebot

Use CURLOPT_RESOLVE to workaround mailgun connection timeout issues

Dec 12th, 2024
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2.     $curl = curl_init();
  3.     curl_setopt($curl, CURLOPT_URL, 'https://api.mailgun.net/v3/filebot.net/messages');
  4.     curl_setopt($curl, CURLOPT_RESOLVE, ['api.mailgun.net:443:34.149.236.64']);
  5.     curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  6.     curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  7.     curl_setopt($curl, CURLOPT_USERPWD, $key);
  8.     curl_setopt($curl, CURLOPT_POST, true);
  9.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  10.     curl_setopt($curl, CURLOPT_POSTFIELDS, [
  11.         'from'         => $from,
  12.         'to'           => $to,
  13.         'subject'      => $subject,
  14.         'text'         => $text,
  15.         'attachment'   => new CURLStringFile($attachment, $filename)
  16.     ]);
  17.  
  18.     $response = curl_exec($curl);
  19.     $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  20.  
  21.     if ($status != 200) {
  22.         error_log('[MAILGUN] '.$status.' '.(curl_errno($curl) ? curl_error($curl) : $response));
  23.     }
  24.  
  25.     curl_close($curl);
  26. ?>
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement