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
  • 24,667
  • 25
  • 136
  • 263
user580950
  • 3,355
  • 12
  • 46
  • 88
  • 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
  • 20,858
  • 7
  • 60
  • 113