php-ews icon indicating copy to clipboard operation
php-ews copied to clipboard

Curl Error 65 - Office 365

Open allforme3 opened this issue 6 years ago • 3 comments

When attaching a document (PDF) to an email on outlook.office365.com. It fails to send returning an error 65 - failed to rewind.

"The cURL request was retried 3 times and did not succeed. The most likely reason for the failure is that cURL was unable to rewind the body of the request and subsequent retries resulted in the same error. Turn on the debug option to see what went wrong. See https://bugs.php.net/bug.php?id=47204 for more information."

allforme3 avatar Mar 11 '19 09:03 allforme3

Well that's interesting. Can you send me the code you're using to attach and send, and tell me how large the PDF is?

Garethp avatar Mar 20 '19 12:03 Garethp

Hello,

Here is the code: try { $mail->getClient()->CreateAttachment([ 'ParentItemId' => $mailId->toArray(), 'Attachments' => [ 'FileAttachment' => [ 'Name' => $attachment['Name'], 'Content' => $attachment['Contents'] ] ], ]); } catch (\Exception $e) { $message = "Failed to Save Attachment: {$attachment['Name']}"; throw new \Exception($message, 0, $e); } Where the $mailID is generated from the sendMail() function and the $attachment is an array containing the string name and the file_get_contents of an file.

I've attached an example file that failed to upload to office365. Error-PDF.pdf

Client is default just with a timeout of 20 seconds.

allforme3 avatar Mar 22 '19 11:03 allforme3

I'm having the same issue. I've narrowed it down and found that it only happens when creating an attachment with this particular PDF (and presumably other particular PDFs), but there's nothing I can figure out that's different with this file compared to others. And it always happens with this PDF. The vast majority of files attach and send correctly with the same code.

Of course it's a customer invoice with personal information on it, so I'd have to get approval before sharing the pdf in question, and I don't know how to replicate it otherwise.

try{$api->getClient()->CreateAttachment(array ( 'ParentItemId' => $mailId->toArray(), 'Attachments' => array ( 'FileAttachment' => array ( 'Name' => "Invoice_729803-00.pdf", 'Content' => file_get_contents('temp/Invoice_729803-00.pdf') ) ), )); } catch (Exception $e){ echo 'Caught exception: ', $e->getMessage(), "\n"; }

PHP Fatal error:  Uncaught GuzzleHttp\Exception\RequestException: cURL error 65: The cURL request was retried 3 times and did not succeed. The most likely reason for the failure is that cURL was unable to rewind the body of the request and subsequent retries resulted in the same error. Turn on the debug option to see what went wrong. See https://bugs.php.net/bug.php?id=47204 for more information. (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) in /php-ews/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:201
Stack trace:
#0 /php-ews/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(537): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)
#1 /php-ews/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(152): GuzzleHttp\Handler\CurlFactory::retryFailedRewind(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Array)
#2 /php-ews/vendor/ in /php-ews/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 201

linkums avatar Sep 30 '21 14:09 linkums