00001 <?php 00002 00024 class Communication 00025 { 00032 public function Communication(iLock $sendLock_) 00033 { 00034 $this->_sendLock = $sendLock_; 00035 } 00036 00072 public function sendEmail($from_, $toArr_, $subject_, $text_, $html_ = NULL) 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 } 00117 00149 public function sendSms($fromEmail_, $fromName_, $toArr_, $message_, $repeatTime_ = 60) 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 } 00173 00180 private $_sendLock; 00181 } 00182 00183 ?>