0

Is it possible to assign $msgArray as a last element of the array which is used in curl

foreach( $attachmentsArray as $att )
    {
        $msgArray["attachment[$x]"] = curl_file_create( $att );
        $x ++;
    }
 curl_setopt($ch, CURLOPT_POSTFIELDS, array(
  'from' => 'Open <test@gmail.com>',
  'to' => $email,
  'subject' => $subject,
  'html' => $msg
));
LF00
  • 27,015
  • 29
  • 156
  • 295
user580950
  • 3,558
  • 12
  • 49
  • 94
  • 1
    [useful information](http://stackoverflow.com/questions/5224790/curl-post-format-for-curlopt-postfields) – Martin Dec 31 '16 at 03:08

1 Answers1

2

Yes. Just as a pump, does this work for you?

foreach( $attachmentsArray as $att )
    {
        $msgArray["attachment[$x]"] = curl_file_create( $att );
        $x ++;
    }

$arrayValues = array(
  'from' => 'Open <test@gmail.com>',
  'to' => $email,
  'subject' => $subject,
  'html' => $msg,
  'attachments' => http_build_query($msgArray)

  /** or an alternative form of collapsing an array into a
     string value, such as json_encode($msgArray);  **/
);


 curl_setopt($ch, CURLOPT_POSTFIELDS, $arrayValues);

reference (recommended)

Martin
  • 22,212
  • 11
  • 70
  • 132