Skip to main content
Question

Which content-type header to use when sending MMS via API

  • December 25, 2024
  • 4 replies
  • 23 views

Forum|alt.badge.img

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?

4 replies

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • 2313 replies
  • December 26, 2024

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.


Forum|alt.badge.img
  • Author
  • New Participant
  • 2 replies
  • December 27, 2024

@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


PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • 2313 replies
  • December 27, 2024

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.


Forum|alt.badge.img
  • Author
  • New Participant
  • 2 replies
  • December 27, 2024

Thank you for the reply!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings