Skip to content

Commit 31cf972

Browse files
lornajaneMark Lewin
authored andcommitted
Update the send SMS block to match new spec (#29)
1 parent 5b80b52 commit 31cf972

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

sms/send-sms.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@
55
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
66
$client = new \Nexmo\Client($basic);
77

8-
$message = $client->message()->send([
9-
'to' => TO_NUMBER,
10-
'from' => 'Acme Inc',
11-
'text' => 'A text message sent using the Nexmo SMS API'
12-
]);
8+
try {
9+
$message = $client->message()->send([
10+
'to' => TO_NUMBER,
11+
'from' => 'Acme Inc',
12+
'text' => 'A text message sent using the Nexmo SMS API'
13+
]);
14+
$response = $message->getResponseData();
15+
16+
if($response['messages'][0]['status'] == 0) {
17+
echo "The message was sent successfully\n";
18+
} else {
19+
echo "The message failed with status: " . $response['messages'][0]['status'] . "\n";
20+
}
21+
} catch (Exception $e) {
22+
echo "The message was not sent. Error: " . $e->getMessage() . "\n";
23+
}
1324

14-
var_dump($message->getResponseData());

0 commit comments

Comments
 (0)