Drupal 8 - Sending Faxes with Twilio

Michalak Drupal Commerce Developer

Yep, you read the title correctly and it says “fax.”  Faxes are still used more than I thought, and it is really cool that Twilio has an API to send and receive faxes that is quite easy to use.

Today in this post I will be talking about sending faxes from your Drupal website.  Which is quite easy and doesn’t take much code to achieve.

I have pulled together a code example from the Twilio API documents and as you can see below there isn’t much there.

use Twilio\Rest\Client;

$twilio = new Client($sid, $token);
$to = “+1234567890”;
$from = “+0987654321”;
$document = “https://example.com/document.pdf”;

$response = twilio->fax->v1->faxes->create($to, $document,["from" => $from]);

A couple of notes on the Twilio fax API:

  • There isn’t much of a response back which can make error handling or logging a little difficult.
  • The document being faxed must be a PDF.


Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.