2016-12-31 11 views
0

にカール

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

はいで使用されている配列の最後の要素として$msgArrayを割り当てることが可能です。これはあなたのために機能するのですか?

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(推奨)