Skip to main content

Hello!

I am using the php SDK to send an MMS with an image attachment (I tried using jpeg/png images). The documentation at https://developers.ringcentral.com/guide/messaging/sms/sending-images#php says: “Therefore, you must use multipart form-data, and set the content-type header to multipart/mixed.” In the same page of the documentation there is an example in php that uses the MultiPartBuilder class from the SDK. However, in the SDK MultiPartBuilder class the content-type header is set to multipart/form-data, not mixed:

The documentation makes it sound as if I can only use multipart/mixed. So which content-type headers can I use to send an MMS?

If you use the RingCentral PHP SDK to send MMS messages, you don’t need to set the request header. Just follow the sample code as such to send your message. The SDK set the content-type to “multipart/form-data” as you could see.

I can check with the dev guide writer to see what that means. But I know that we support both /form-data  and mixed content types.


@PhongVu unfortunately when i use the example from the SDK I get a 400 bad request error. The body of the error response contains <html> that says: bad request cloudfare. When i change the header to multipart/mixed the error disappears (I get the error “This feature is not available” which i expect since this is a development account). Therefore? I thought the issue was with the inccorrect content-type and wanted to double check here


I am sure that it’s because of the sandbox environment which is no longer support SMS/MMS.

This code works perfect for me on production environment.

function send_mms($fromNumber){
global $platform, $rcsdk;
global $RECIPIENT;
try {
$bodyParams = array(
'from' => array( 'phoneNumber' => $fromNumber ),
'to' => array( array('phoneNumber' => $RECIPIENT ) ),
'text' => 'Hello World!'
);

$endpoint = "/account/~/extension/~/mms";
$request = $rcsdk->createMultipartBuilder()
->setBody( $bodyParams )
->add(fopen(__DIR__.'/test.jpg', 'r'))
->request($endpoint);

$resp = $platform->sendRequest($request);
print_r ("SMS sent. Message status: " . $resp->json()->messageStatus . PHP_EOL);
}catch (\RingCentral\SDK\Http\ApiException $e) {
// Getting error messages using PHP native interface
print 'Expected HTTP Error: ' . $e;
print ' Message: ' . $e->apiResponse->response()->error() . PHP_EOL;
}
}

So if you have a production account, please test again.


Thank you for the reply!


Reply