I have service called "sms" that I need to use it multiple times in it's controller:
$this->get('sms')->send($userCard->getUser()->getMobile(), "text to send for first time");
$this->get('sms')->send($userCard->getUser()->getMobile(), "my second text to send");
but always it send first message twice, what should I do?
class SmsListener {
private $url="http://www.smsprovider.com/URLSend.aspx?Username=adminuser&Password=addminpassword&PortalCode=6496&Flash=0&Message=%s&Mobile=%s";
public function __construct() {
}
//put your code here
public function send($mobile,$message) {
$this->url=sprintf($this->url,$message,$mobile);
$url = str_replace(" ", '%20', $this->url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$ret=curl_exec($ch);
return $ret;
}
}
generate your url inside the function like this:
class SmsListener {
public function __construct() {
}
//put your code here
public function send($mobile,$message) {
$baseUrl=$url="http://www.smsprovider.com/URLSend.aspx?Username=adminuser&Password=addminpassword&PortalCode=6496&Flash=0&Message=%s&Mobile=%s";
$url=sprintf($baseUrl,$message,$mobile);
$url = str_replace(" ", '%20', $url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$ret=curl_exec($ch);
return $ret;
}
}