Ok, I fixed it: I think we should set the CURLOPT_POST before CURLOPT_POSTFIELDS
Correct
curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
Incorrect
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);curl_setopt($ch, CURLOPT_POST, true);