We can even validate the phone number using
some pattern. But for now, let's perform basic cleanups of removing spaces
and the '+' sign from the number. The following code shows the Send and
CleanUpPhoneNumber functions.
public function CleanUpPhoneNumber($phone)
{
$phone = trim($phone);
$phone = str_replace(" ", "", $phone);
$phone = str_replace("+", "", $phone);
return $phone;
}
public function Send($to, $from, $msg)
{
$command = "sendmsg";
$to = $this->CleanUpPhoneNumber($to);
if ($to == "")
{
return 0;
Chapter 6
[ 107 ]
}
$params['to'] = $to;
$params['from'] = $from;
$params['text'] = $msg;
$message = new Message();
if ($this->Request($command, $params))
{
return $this->lastResult;
}
return 0;
}
4. The important parts here are the "sendmsg" command, and to, from, and text
parameters. They tell Clickatell to queue the message for delivery.
5. Let us modify our processOrders.inc.php and add SMS sending to it.
When the status is changed from new to processing, we will send a message
to the customer, notifying her or him that the pizzas are on their way! To do
this, initialize an SMSGateway object, authenticate with the gateway, and then
send out messages in a loop.
Pages:
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150