Office365 Attachment Missing issue in Code Igniter 3 PHP

Adele Vance 0 Reputation points

Office365 Attachment Missing issue in Code Igniter 3 PHP

Flow: When an email is sent using Office365, a draft is initially created. All the attachments are then added to this draft one by one before it is sent to the recipient.

Issue: We noticed that when attachments are uploaded to an Office365 email, they don’t always have sufficient time to attach properly before the email is sent. This results in some attachments not being included in the sent email.

Solution Implemented: To address this, we have implemented a delay for each attachment based on its size to ensure it attaches properly to the email. However, we observed that this solution may not always work when there are many attachments or when there are multiple users sending emails through that mail.

Please help me in resolving this issue.

Below is my code-

$responseSession = $graph->createRequest("POST", "/me/messages/".$messageId."/attachments/createUploadSession")->attachBody($mailBodySession)->execute();            

$responseSessionBody = $responseSession->getBody();            
$messageSessionUrl = $responseSessionBody['uploadUrl'];    
$curl = curl_init();                                    

curl_setopt_array($curl, array(CURLOPT_URL => $messageSessionUrl,                    CURLOPT_RETURNTRANSFER => true,CURLOPT_ENCODING => '',                    CURLOPT_MAXREDIRS => 10,CURLOPT_TIMEOUT => 0,CURLOPT_FOLLOWLOCATION => true,CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,CURLOPT_CUSTOMREQUEST => 'PUT',CURLOPT_POSTFIELDS => substr($file_contents, $start, $end + 1),                    CURLOPT_HTTPHEADER => array('Content-Type: application/octet-stream',                      'Content-Length: '. $length,'Content-Range: bytes '.$start.'-'.$end.'/'.$totalSizeInBytesNew)));                 

$response = curl_exec($curl);                  

$response = $graph->createRequest("POST", "/me/messages/".$messageId."/send")
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,115 questions
0 comments No comments
{count} votes