通过 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, please log in to <a href='http://www.demo.mysite.com' target='_blank'>www.demo.mysite.com</a> 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);
传真正在发送,但传真中的内容没有按照我们希望的格式进行格式化。传真中的内容类似于:
Notification Lorem epsum Lorem epsum Lorem epsum Lorem epsum My Site Lorem epsum Lorem epsumLorem epsumLorem epsumLorem epsum Lorem epsumLorem epsumLorem epsum To view more and print more details, please log in to www.demo.mysite.com using your email address.Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum.
我很确定它一定是标头类型或没有正确设置的东西,这就是 RingCentral API 表现得这样的原因。
提前致谢。