title: Curl Email intermittently failing to send
body: <p>I have been using the following code to send daily emails to 3 different addresses using curl and PHP on POST via MailJet. The emails appeared to be sending successfully and contain accurate data. However, I find that there are occasions when not all three emails go through. For example, for the past three days, emails were being sent to 2 out of 3 email addresses. However, today the email went to all 3 addresses successfully. I have checked my MailJet reports as well to verify that the emails weren't being blocked on their end, and am not seeing the missing emails there either.</p>
  <p>Any ideas on why this could be happening? I attempted to add a &quot;sleep&quot; delay of 10 second in an attempt to keep the emails from being sent too quickly, but was still experiencing the same issue.</p>
  <p>Also, this was my first time using curl... and I was only successful at getting multiple emails to send by repeating my curl code altogether. Any insight on how to reduce the amount of code would be greatly appreciated.</p>
  <pre><code>//Send Email Notification Using 
  //First Email Address
  $body = [
      'Messages' =&gt; [
          [
          'From' =&gt; [
              'Email' =&gt; &quot;email@gmail.com&quot;,
              'Name' =&gt; &quot;IT Dept&quot;
          ],
          'To' =&gt; [
              [
                  'Email' =&gt; &quot;email1@gmail.com&quot;,
                  'Name' =&gt; &quot;Recipiant1&quot;
              ],
          ],
  
          'Subject' =&gt; &quot;Your Daily Data is Here&quot;,
          'HTMLPart' =&gt; &quot;&lt;center&gt;&lt;h2&gt;Your Daily Work Totals are Below:&lt;/h2&gt;&lt;/center&gt;&lt;br /&gt;  &quot; . &quot; &lt;h2&gt;Entry Date/Time:&lt;/h2&gt; &quot; . date(&quot;F j, Y, g:i a&quot;)  . &quot; &lt;h2&gt;Order:&lt;/h2&gt; &quot; . $_POST['Order_Quantity'] . &quot; &lt;h2&gt;Product:&lt;/h2&gt; &quot; . $_POST['Product_Quantity'] . &quot;&lt;h2&gt;Employee Count:&lt;/h2&gt; &quot; . $_POST['Crew_Count'] . &quot; &lt;h2&gt;Daily Total:&lt;/h2&gt; &quot; . $sum = array_sum($_SESSION) . &quot; &lt;center&gt;&lt;h2&gt;Link to Report:&lt;/h2&gt;&lt;/center&gt; &lt;h3&gt;google.com&lt;/h3&gt; &quot; 
          ]
      ]
  ];
  
  $ch = curl_init();
    
  curl_setopt($ch, CURLOPT_URL, &quot;https://api.mailjet.com/v3.1/send&quot;);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
      'Content-Type: application/json')
  );
  
      
  curl_setopt($ch, CURLOPT_USERPWD, &quot;gjirhhighighihihighrihihrihgirghihihihihihih&quot;);
  
  $server_output = curl_exec($ch);
  
  curl_close ($ch);
  sleep(10);
  }
  //Fetch Results
  
  $response = json_decode($server_output);
  if ($response-&gt;Messages[0]-&gt;Status == 'success' )  {
      echo &quot;Email sent successfully.&quot;;
  }
  
    //Second Email Address
  $body = [
      'Messages' =&gt; [
          [
          'From' =&gt; [
              'Email' =&gt; &quot;fromemail@gmail.com&quot;,
              'Name' =&gt; &quot;IT Dept&quot;
          ],
          'To' =&gt; [
              [
                  'Email' =&gt; &quot;email2@gmail.com&quot;,
                  'Name' =&gt; &quot;Recipiant2&quot;
              ],
          ],
  
          'Subject' =&gt; &quot;Your Daily Data is Here&quot;,
          'HTMLPart' =&gt; &quot;&lt;center&gt;&lt;h2&gt;Your Daily Work Totals are Below:&lt;/h2&gt;&lt;/center&gt;&lt;br /&gt;  &quot; . &quot; &lt;h2&gt;Entry Date/Time:&lt;/h2&gt; &quot; . date(&quot;F j, Y, g:i a&quot;)  . &quot; &lt;h2&gt;Order:&lt;/h2&gt; &quot; . $_POST['Order_Quantity'] . &quot; &lt;h2&gt;Product:&lt;/h2&gt; &quot; . $_POST['Product_Quantity'] . &quot;&lt;h2&gt;Employee Count:&lt;/h2&gt; &quot; . $_POST['Crew_Count'] . &quot; &lt;h2&gt;Daily Total:&lt;/h2&gt; &quot; . $sum = array_sum($_SESSION) . &quot; &lt;center&gt;&lt;h2&gt;Link to Report:&lt;/h2&gt;&lt;/center&gt; &lt;h3&gt;google.com&lt;/h3&gt; &quot; 
          ]
      ]
  ];
  
  $ch = curl_init();
    
  curl_setopt($ch, CURLOPT_URL, &quot;https://api.mailjet.com/v3.1/send&quot;);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
      'Content-Type: application/json')
  );
  
      
  curl_setopt($ch, CURLOPT_USERPWD, &quot;gjirhhighighihihighrihihrihgirghihihihihihih&quot;);
  
  $server_output = curl_exec($ch);
  
  curl_close ($ch);
  sleep(10);
  }
  //Fetch Results
  
  $response = json_decode($server_output);
  if ($response-&gt;Messages[0]-&gt;Status == 'success' )  {
      echo &quot;Email sent successfully.&quot;;
  }
  //Third Email Address
  $body = [
      'Messages' =&gt; [
          [
          'From' =&gt; [
              'Email' =&gt; &quot;fromemail@gmail.com&quot;,
              'Name' =&gt; &quot;IT Dept&quot;
          ],
          'To' =&gt; [
              [
                  'Email' =&gt; &quot;email3@gmail.com&quot;,
                  'Name' =&gt; &quot;Recipiant3&quot;
              ],
          ],
  
          'Subject' =&gt; &quot;Your Daily Data is Here&quot;,
          'HTMLPart' =&gt; &quot;&lt;center&gt;&lt;h2&gt;Your Daily Work Totals are Below:&lt;/h2&gt;&lt;/center&gt;&lt;br /&gt;  &quot; . &quot; &lt;h2&gt;Entry Date/Time:&lt;/h2&gt; &quot; . date(&quot;F j, Y, g:i a&quot;)  . &quot; &lt;h2&gt;Order:&lt;/h2&gt; &quot; . $_POST['Order_Quantity'] . &quot; &lt;h2&gt;Product:&lt;/h2&gt; &quot; . $_POST['Product_Quantity'] . &quot;&lt;h2&gt;Employee Count:&lt;/h2&gt; &quot; . $_POST['Crew_Count'] . &quot; &lt;h2&gt;Daily Total:&lt;/h2&gt; &quot; . $sum = array_sum($_SESSION) . &quot; &lt;center&gt;&lt;h2&gt;Link to Report:&lt;/h2&gt;&lt;/center&gt; &lt;h3&gt;google.com&lt;/h3&gt; &quot; 
          ]
      ]
  ];
  
  $ch = curl_init();
    
  curl_setopt($ch, CURLOPT_URL, &quot;https://api.mailjet.com/v3.1/send&quot;);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
      'Content-Type: application/json')
  );
  
      
  curl_setopt($ch, CURLOPT_USERPWD, &quot;gjirhhighighihihighrihihrihgirghihihihihihih&quot;);
  
  $server_output = curl_exec($ch);
  
  curl_close ($ch);
  sleep(10);
  }
  //Fetch Results
  
  $response = json_decode($server_output);
  if ($response-&gt;Messages[0]-&gt;Status == 'success' )  {
      echo &quot;Email sent successfully.&quot;;
  }
  </code></pre>