question

fax number avatar image
fax number asked Phong Vu answered

Sending fax with php code, Fax sending without attachments.

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_URL, "https://platform.ringcentral.com/restapi/oauth/token");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, "username=+xxxxxx&password=password#&extension=102&grant_type=password");

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_USERPWD, "PYS9kaDdSey5j72ljRCfDw" . ":" . "JV4wWOkJTX5sJf-OZDD_fgJJ-uZODeSPeXxdhMUtsTAN");


$headers = array();

$headers[] = "Accept: application/json";

$headers[] = "Content-Type: application/x-www-form-urlencoded";

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);


$result = curl_exec($ch);

$results = (json_decode($result));

$token = $results -> access_token;


$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_URL, "https://platform.ringcentral.com/restapi/v1.0/account/~/extension/~/fax");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POST,1);

curl_setopt($ch, CURLOPT_POSTFIELDS, array(

'from' => '+xxxxx',

'to' => '+xxxxxx',

'name'=>'sample.pdf',

'attachments'=> '@'.realpath('sample.pdf'),

'coverpagetext' => 'PHP FaxOut Via cURL'

));

$headers = array();

$headers[] = "Accept: application/json";

$headers[] = "Accept: application/pdf";

$headers[] = "Authorization: Bearer $token";

$headers[] = "Content-Type: multipart/form-data";

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);


$result1 = curl_exec($ch);

print_r($result1);


if (curl_errno($ch)) {

echo 'Error:' . curl_error($ch);

}

curl_close ($ch);


?>


Response


{ "uri" : "https://platform.ringcentral.com/restapi/v1.0/account/628394008/extension/628447008/message-store/986620102017", "id" : 986620102017, "to" : [ { "phoneNumber" : "+12158600723", "location" : "Newtown, PA", "messageStatus" : "Queued" } ], "type" : "Fax", "creationTime" : "2019-05-29T07:09:48.000Z", "readStatus" : "Unread", "priority" : "Normal", "attachments" : [ { "id" : 986620102017, "uri" : "https://media.ringcentral.com/restapi/v1.0/account/628394008/extension/628447008/message-store/986620102017/content/986620102017", "type" : "RenderedDocument", "contentType" : "application/pdf" } ], "direction" : "Outbound", "availability" : "Alive", "messageStatus" : "Queued", "faxResolution" : "High", "faxPageCount" : 0, "lastModifiedTime" : "2019-05-29T07:09:48.752Z", "coverIndex" : 7 }

getting started
2 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image Phong Vu ♦♦ commented ·

What is your question? Or is that you just want to share your code?

0 Likes 0 ·
fax number avatar image fax number Phong Vu ♦♦ commented ·

The fax was sending without attachments, only cover page sending.

0 Likes 0 ·

1 Answer

Phong Vu avatar image
Phong Vu answered

Sorry I did not understand the question from the title.

It is not the way to send file attachments like that. There is no boundary attached to multipart-form-data either.

Is there a reason why you have to use curl to send a fax? Using the RingCentral PHP SDK would help you simply your code and handle lots of overhead exception handlings. Look at this quick start to see how easy to send a fax using the SDK.

If you insist to use curl, let me know so I can spare some time to write it for you or read this

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys