Communication Class Reference
[General]

Sends SMS and Email messages. More...

List of all members.

Public Member Functions

 Communication (iLock $sendLock_)
 Constructor.
 sendEmail ($from_, $toArr_, $subject_, $text_, $html_=NULL)
 Send an email.
 sendSms ($fromEmail_, $fromName_, $toArr_, $message_, $repeatTime_=60)
 Sends an SMS message to a mobile phone.

Private Attributes

 $_sendLock
 A lock object that will handle how often an SMS can be sent.


Detailed Description

Sends SMS and Email messages.

This class uses Rmail written by Richard Heyes at www.phpguru.org. The documentation can be found here. http://www.phpguru.org/downloads/Rmail/Rmail%20for%20PHP/docs.html

An installation of the Rmail package are included in fareofficelib, to minimize any hazzle getting fareofficelib up and working. But the copyright for Rmail is still owned by Richard Heyes.

Example: $sendLock = new FileLock('/tmp/locks/'); $communication = new Communication($sendLock); $communication->sendSms('monitor.fareoffice.com', '0731234567', 'Hello world);

Author:
Daniel Lindh <[email protected]>

Definition at line 24 of file Communication.class.php.


Member Function Documentation

Communication::Communication ( iLock $  sendLock_  ) 

Constructor.

Parameters:
$sendLock_ - iLock - A lock object that will handle how often an SMS can be sent.

Definition at line 32 of file Communication.class.php.

00033   {
00034     $this->_sendLock = $sendLock_;
00035   }

Communication::sendEmail ( from_,
toArr_,
subject_,
text_,
html_ = NULL 
)

Send an email.

Supports both plain text and html messages.

Parameters:
$from_ - string - The from email address. Ie. info(at)example.com
$toArr_ - array - The to email addresses, can be many. $toArr_[] = 'daniel(at)example.com'; $toArr_[] = 'support(at)example.com';
$subject_ - string - The email subject.
$text_ - string - The text part of the email.
An email can have both a text and an html part, the html part will be read if the email client supports html, or else the text part will be used.

This argument and/or $html needs to be used, if this argument is empty the $html_ will be used for the text part of the message but with striped html tags.

Parameters:
$html_ - string - The HTML part of the email.
Returns:
- string - errorMessage If sendEmail fails, an error message will be returned. If sendEmail succededs, false will be returned.

Definition at line 72 of file Communication.class.php.

Referenced by sendSms().

00073   {
00074     if (!empty($from_) && !empty($toArr_) && !empty($subject_) && (!empty($text_) || !empty($html_)))
00075     {
00076       $mail = new Rmail();
00077 
00078       if (!empty($html_))
00079       {
00080         if (empty($text_))
00081         {
00082           $text_ = strip_tags($html_);
00083         }
00084 
00085         $mail->setHTML($html_, $text_);
00086       }
00087       else
00088       {
00089         $mail->setText($text_);
00090       }
00091 
00092       $mail->setReturnPath($from_);
00093       $mail->setFrom($from_);
00094       $mail->setSubject($subject_);
00095 
00096       if (!is_array($toArr_))
00097       {
00098         $toArr_ = array($toArr_);
00099       }
00100 
00101       $mailResult = $mail->send($toArr_);
00102 
00103       if (!$mailResult)
00104       {
00105         return 'Failed to send mail';
00106       }
00107       else
00108       {
00109         return false;
00110       }
00111     }
00112     else
00113     {
00114       return 'Failed to send mail, one or more parameters wasn\'t entered.';
00115     }
00116   }

Communication::sendSms ( fromEmail_,
fromName_,
toArr_,
message_,
repeatTime_ = 60 
)

Sends an SMS message to a mobile phone.

The function uses the (at)esms.nu service.

Parameters:
$fromEmail_ - string - esms requires all sms-emails to be sent from a registered email-address. Ie. sms(at)example.com
$fromName_ - string - The from name that will be displayed in the SMS Ie. Daniel 0731234567
$toArr_ - string - A list of cell phone numbers that will recieve the message. Ie. 0731234567
$message_ - string - The text that will be sent on the sms. The message will be truncated to 160 chars.
$repeatTime_ - integer The number of seconds to wait until next sms can be sent. To prevent sms flooding.
Returns:
$errorMessage - string - If sendEmail fails, an error message will be returned. If sendEmail succededs, false will be returned.

Definition at line 149 of file Communication.class.php.

References sendEmail().

00150   {
00151     if (!empty($message_))
00152     {
00153       $message_ = substr($message_, 0, 160);
00154       if (!empty($this->_sendLock) || $this->_sendLock->isLockExpired('SMS', $repeatTime_, false))
00155       {
00156         $cellPhoneArr = array();
00157         if (!is_array($toArr_))
00158         {
00159           $toArr_ = array($toArr_);
00160         }
00161         foreach ($toArr_ as $cellPhone)
00162         {
00163           $cellPhoneArr[] = $cellPhone . '@esms.nu';
00164         }
00165         return $this->sendEmail($fromEmail_, $cellPhoneArr, $fromName_, $message_);
00166       }
00167       else
00168       {
00169         return 'Failed to send sms, to many at to short time.';
00170       }
00171     }
00172   }


Member Data Documentation

Communication::$_sendLock [private]

A lock object that will handle how often an SMS can be sent.

$_sendLock - ILock -

Definition at line 180 of file Communication.class.php.


The documentation for this class was generated from the following file:

Generated on Wed May 6 23:28:24 2009 for fareofficelib by  doxygen 1.5.8