Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用RingCentral API发送传真时HTML内容的正确格式_Php_Html_Zend Framework_Fax_Ringcentral - Fatal编程技术网

Php 使用RingCentral API发送传真时HTML内容的正确格式

Php 使用RingCentral API发送传真时HTML内容的正确格式,php,html,zend-framework,fax,ringcentral,Php,Html,Zend Framework,Fax,Ringcentral,通过RingCentral API发送的传真HTML内容未按正确顺序格式化 我使用的代码是: // The HTML content to be sent $html = "<h3>Notification</h3><div>Lorem epsum Lorem epsum Lorem epsum Lorem epsum <b>My Site</b>Lorem epsum Lorem epsum</div>&l

通过RingCentral API发送的传真HTML内容未按正确顺序格式化

我使用的代码是:

    // The HTML content to be sent
    $html = "<h3>Notification</h3><div>Lorem epsum Lorem epsum Lorem epsum Lorem epsum <b>My Site</b>Lorem epsum Lorem epsum</div><div><br></div><div>Lorem epsumLorem epsumLorem epsum<i><b>Lorem epsumLorem epsumLorem epsum</b></i>.</div><div><br></div><div>To view more and print more details,&nbsp;please log in to&nbsp;<a href='http://www.demo.mysite.com' target='_blank'>www.demo.mysite.com</a>&nbsp;using your email address.</div><div><br></div><div>Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</div>";

    // Creating a file
    $fileRand = rand();
    $filename = 'faxfile_'.$fileRand.'.html';

    // Open the file in write mode
    $faxFile = fopen('ringfax/'.$filename, 'w');

    // Write the contents to the html file.
    fwrite($faxFile, $html);

    // Close the file.
    fclose($faxFile);

    // Setting up data for the RingCentral API
    $faxData['Username']  = "XXXXXXXXXX";
    $faxData['Password']  = "XXXXXXXXXX";
    $faxData['Recipient'] = "XXXXXXXXXX";   
    $faxData['Sendtime']  = gmdate('d:m:y h:m');
    $faxData['Coverpage'] = 0;
    $faxData['Attachment'] = '@'.realpath('ringfax/'.$filename).';filename='.$filename.';content-type=text/html';

    // Open connection
    $ch = curl_init();

    // Set the url, number of POST vars and other data
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_URL, 'https://service.ringcentral.com/faxapi.asp?');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: text/html", "charset: UTF-8"));
    curl_setopt($ch, CURLOPT_POST, count($faxData));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $faxData);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Execute post
    $result = curl_exec($ch);

    // Receives curl error
    $cErr = curl_error($ch);
    // curl curl info
    $cInfo = curl_getinfo($ch); 

    // Write the error to the log file
    ini_set("log_errors", 1);
    ini_set("error_log", "logs/ring_central_error");
    error_log($result);

    //close connection
    curl_close($ch);

    // Delete the file
    unlink('ringfax/'.$filename);
我很确定它一定是标头类型或某些未正确设置的类型,这就是为什么RingCentral API的行为是这样的


提前感谢。

看起来您正在使用旧版本的传真API。请看一下《开发者指南》中的API:


您还可以将RingCentral PHP SDK用于新API,该API将创建格式正确的请求:

  • GitHub:
  • 包装商:
下面是来自
README.md
的一些PHP代码:

$request = $rcsdk->createMultipartBuilder()
                 ->setBody(array(
                     'to' => array(
                         array('phoneNumber' => '16501112233'),
                     ),
                     'faxResolution' => 'High',
                 ))
                 ->add('Plain Text', 'file.txt')
                 ->add(fopen('path/to/file', 'r'))
                 ->request('/account/~/extension/~/fax'); // also has optional $method argument

$response = $platform->sendRequest($request);
$request = $rcsdk->createMultipartBuilder()
                 ->setBody(array(
                     'to' => array(
                         array('phoneNumber' => '16501112233'),
                     ),
                     'faxResolution' => 'High',
                 ))
                 ->add('Plain Text', 'file.txt')
                 ->add(fopen('path/to/file', 'r'))
                 ->request('/account/~/extension/~/fax'); // also has optional $method argument

$response = $platform->sendRequest($request);