Net_SMS
[ class tree: Net_SMS ] [ index: Net_SMS ] [ all elements ]

Source for file generic_smtp.php

Documentation is available at generic_smtp.php

  1. <?php
  2. /**
  3.  * Generic e-mail based SMS driver
  4.  *
  5.  * Copyright 2005 WebSprockets, LLC
  6.  *
  7.  * See the enclosed file COPYING for license information (LGPL). If you did
  8.  * not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  9.  *
  10.  * This driver interfaces with the email-to-sms gateways provided by many
  11.  * carriers, particularly those based in the U.S.
  12.  *
  13.  * @category   Networking
  14.  * @package    Net_SMS
  15.  * @author     Ian Eure <ieure@php.net>
  16.  * @since      Horde 3.1
  17.  * @since      Net_SMS 0.0.2
  18.  */
  19. class Net_SMS_generic_smtp extends Net_SMS
  20. {
  21.     /**
  22.      * Capabilities of this driver.
  23.      *
  24.      * @var array $capabilities 
  25.      */
  26.     var $capabilities = array(
  27.         'auth'        => false,
  28.         'batch'       => false,
  29.         'multi'       => false,
  30.         'receive'     => false,
  31.         'credit'      => false,
  32.         'addressbook' => false,
  33.         'lists'       => false
  34.     );
  35.  
  36.     /**
  37.      * Driver parameters.
  38.      *
  39.      * @var array $_params 
  40.      *
  41.      * @access private
  42.      */
  43.     var $_params = array(
  44.         'carrier'     => null,
  45.         'mailBackend' => 'mail',
  46.         'mailParams'  => array(),
  47.         'mailHeaders' => array()
  48.     );
  49.  
  50.     /**
  51.      * Carrier email map.
  52.      *
  53.      * @var array  $_carriers 
  54.      *
  55.      * @access private
  56.      */
  57.     var $_carriers = array(
  58.         /* U.S. carriers. */
  59.         'att'          => '%s@mobile.att.net',
  60.         'cingular'     => '%s@mobile.mycingular.com',
  61.         'verizon'      => '%s@vtext.com',
  62.         'boost'        => '%s@myboostmobile.com',
  63.         'cellularone'  => '%s@mycellone.net',
  64.         'cincybell'    => '%s@gocbw.com',
  65.         'sprint'       => '%s@messaging.sprintpcs.com',
  66.         'tmobile_us'   => '%s@tmomail.com',
  67.         'suncom'       => '%s@tms.suncom.com',
  68.         'aircel'       => '%s@airsms.com',
  69.         'airtel'       => '%s@airtelmail.com',
  70.         'bplmobile'    => '%s@bplmobile.com',
  71.         'bellmobility' => '%s@txt.bellmobility.ca',
  72.         'bluegrass'    => '%s@sms.bluecell.com',
  73.         'cellforce'    => '%s@celforce.com',
  74.         'cellularone'  => '%s@mycellone.net',
  75.         /* German carriers. */
  76.         'eplus'       => '%s@smsmail.eplus.de',
  77.         'tmobile_de'  => '%s@t-mobile-sms.de',
  78.         'vodafone_de' => '%s@vodafone-sms.de',
  79.     );
  80.  
  81.     /**
  82.      * Identifies this driver.
  83.      *
  84.      * @return array  Driver info.
  85.      */
  86.     function getInfo()
  87.     {
  88.         return array(
  89.             'name' => _("Email-to-SMS Gateway"),
  90.             'desc' => _("EMail-to-SMS gateway driver, for carriers which provide this service.")
  91.         );
  92.     }
  93.  
  94.     /**
  95.      * Returns required parameters.
  96.      *
  97.      * @return array  Array of required parameters.
  98.      */
  99.     function getParams()
  100.     {
  101.         return array(
  102.             'carrier'     => array('label' => _('Carrier')'type' => 'text'),
  103.             'mailBackend' => array('label' => _('PEAR::Mail backend')'type' => 'text')
  104.         );
  105.     }
  106.  
  107.     /**
  108.      * Sends the message.
  109.      *
  110.      * You may also specify the carrier with the 'carrier' key of the message
  111.      * to avoid creating a new instance for each carrier, or fiddling with the
  112.      * parameters.
  113.      *
  114.      * @param array $message  Message to send.
  115.      * @param string $to      Destination phone number.
  116.      *
  117.      * @return boolean  True on success, PEAR_Error on failure.
  118.      *
  119.      * @access private
  120.      */
  121.     function &_send(&$message$to)
  122.     {
  123.         $response = array();
  124.         $destemail $this->_getDest($to);
  125.         require_once 'Mail.php';
  126.         $m =Mail::factory($this->_params['mailBackend']$this->_params['mailParams']);
  127.  
  128.         if (isset($message['carrier'])) {
  129.             $dest $this->_getDest($to$message['carrier']);
  130.         else {
  131.             $dest $this->_getDest($to);
  132.         }
  133.  
  134.         $res =$m->send($dest$this->_params['mailHeaders']$message['text']);
  135.         if (PEAR::isError($res)) {
  136.             $response[$to= array(false$res->getMessage());
  137.         else {
  138.             $response[$to= array(truenull);
  139.         }
  140.  
  141.         return $response;
  142.     }
  143.  
  144.     /**
  145.      * Returns destination e-mail address.
  146.      *
  147.      * @param string $phone  Phone number to send to.
  148.      *
  149.      * @return string  Destination address.
  150.      */
  151.     function _getDest($phone$carrier = null)
  152.     {
  153.         $carrier is_null($carrier$this->_params['carrier'$carrier;
  154.         return sprintf($this->_carriers[$carrier],
  155.                        preg_replace('/[^0-9]/'''$phone));
  156.     }
  157.  
  158.     /**
  159.      * Returns the address template for a carrier.
  160.      *
  161.      * @param string $carrier  Carrier name.
  162.      *
  163.      * @return mixed  Address template or false.
  164.      */
  165.     function getAddressTemplate($carrier)
  166.     {
  167.         if (!isset($this->_carriers[$carrier])) {
  168.             return false;
  169.         }
  170.         return $this->_carriers[$carrier];
  171.     }
  172.  
  173.     /**
  174.      * Adds a carrier to the list.
  175.      *
  176.      * Address templates need to be in the form of an email address, with a
  177.      * '%s' representing the place where the destination phone number goes.
  178.      *
  179.      * @param string $name  Carrier name.
  180.      * @param string $addr  Address template.
  181.      */
  182.     function addCarrier($name$addr)
  183.     {
  184.         $this->_carriers[$name$addr;
  185.     }
  186. }

Documentation generated on Mon, 11 Mar 2019 14:21:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.