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. |
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);
Definition at line 24 of file Communication.class.php.
Communication::Communication | ( | iLock $ | sendLock_ | ) |
Constructor.
$sendLock_ | - iLock - A lock object that will handle how often an SMS can be sent. |
Definition at line 32 of file Communication.class.php.
Communication::sendEmail | ( | $ | from_, | |
$ | toArr_, | |||
$ | subject_, | |||
$ | text_, | |||
$ | html_ = NULL | |||
) |
Send an email.
Supports both plain text and html messages.
$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. |
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.
$html_ | - string - The HTML part of the email. |
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.
$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. |
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 }
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.