2016-12-31 47 views
0

是否有可能分配$msgArray作爲在捲曲

foreach($attachmentsArray as $att) 
    { 
     $msgArray["attachment[$x]"] = curl_file_create($att); 
     $x ++; 
    } 
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'from' => 'Open <[email protected]>', 
    'to' => $email, 
    'subject' => $subject, 
    'html' => $msg 
)); 
+1

[有用的信息(http://stackoverflow.com/questions/5224790/curl-post-format-for-curlopt-postfields) – Martin

回答

2

是所使用的陣列的最後一個元素。就像泵一樣,這是否適合你?

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

$arrayValues = array(
    'from' => 'Open <[email protected]>', 
    '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(推薦)