/** * Sends a message. * * @param Sms_Message $message * @throws Sms_Backend_Exception * @return Sms_Backend_Email */ public function send(Sms_Message $message) { if ($user = $message->getUser()) { $this->setUserSettings($user); } if ($this->target === null && $this->targetEmail === null) { throw new Sms_Backend_Exception('Missing target.'); } if ($this->targetEmail === null) { if (!$message->getPhoneNumber()) { throw new Sms_Backend_Exception('Missing phone number.'); } $targetEmail = str_replace('{n}', $message->getPhoneNumber(), $this->target); } else { $targetEmail = $this->targetEmail; } $mail = $this->getMail(); try { $mail->addTo($targetEmail)->setSubject($message->getSubject())->setBodyText($message->getMessage())->send(); return true; } catch (Exception $e) { return false; } }
public function send(Sms_Message $message) { if ($user = $message->getUser()) { if (!($to = $this->getUserPhone($user))) { throw new Sms_Backend_Exception('Can not determine user number.'); } } else { $to = $message->getPhoneNumber(); } $soap = $this->getSoapClient(); $args = array('session_id' => $this->getSessionId(), 'api_id' => null, 'user' => null, 'password' => null, 'to' => array($to), 'from' => null, 'text' => $message->getSubject() . ': ' . $message->getMessage()); $response = $soap->__soapCall('sendMsg', $args); if (is_array($response)) { foreach ($response as $rspLine) { if (substr_count($rspLine, 'ERR') > 0) { throw new Sms_Backend_Exception($response); } } } elseif (substr_count($response, 'ERR') > 0) { throw new Sms_Backend_Exception($response); } return true; }