You are here

function twilio_send in Twilio 7

Sends a message via Twilio.

Parameters

string $number: The phone number of the recipient

string $message: The message to send to the recipient

string $country: The country code for the phone number

string $media: Public facing url to an media file

array $options: Additonal options (not currently used)

Return value

bool TRUE or FALSE if the message was successfully sent.

6 calls to twilio_send()
twilio_admin_test_form_submit in ./twilio.admin.inc
Submit handler for the administrative test message testing form.
twilio_rules_action_send_sms_to_all_users in ./twilio.rules.inc
Action: Send an SMS to all users.
twilio_rules_action_send_sms_to_number in ./twilio.rules.inc
Action: Send an SMS to a number.
twilio_rules_action_send_sms_to_user in ./twilio.rules.inc
Action: Send an SMS to a user.
twilio_send_sms_to_user_action in ./twilio.actions.inc
Callback function for sending sms to user action.

... See full list

File

./twilio.module, line 142
Twilio module

Code

function twilio_send($number, $message, $country = TWILIO_DEFAULT_COUNTRY_CODE, $media = NULL, $options = array()) {
  switch (variable_get('twilio_long_sms', TWILIO_SMS_LONG_MULTIPLE)) {
    case TWILIO_SMS_LONG_TRUNCATE:

      // Truncate the message to 160 characters.
      $message_truncated = substr($message, 0, 160);
      $response = twilio_command('sendmsg', array(
        'country' => $country,
        'number' => $number,
        'message' => $message_truncated,
        'media' => $media,
        'options' => $options,
      ));
      break;
    case TWILIO_SMS_LONG_MULTIPLE:

      // Break up the message into 160 character chunks and send multiple.
      $iterator = ceil(strlen($message) / 160);
      for ($i = 0; $i < $iterator; $i++) {
        $sms = array(
          'country' => $country,
          'number' => $number,
          'message' => substr($message, $i * 160, 160),
          'options' => $options,
        );

        // Attach the media array only to the first message.
        if ($i === 0) {
          $sms['media'] = $media;
        }
        $response = twilio_command('sendmsg', $sms);
      }
      break;
  }
  return $response;
}