所以我使用Twilio API发送短信。
保持Twilio失败后发送短信?
我从我的数据库中获取usr名称和nr,我把它放在一个PHP数组中。
然后我发短信与foreach循环:
foreach ($usrs as $number => $name) {
$sms = $client->account->messages->create($number,
array(
'from' => "xxxxxxxxxxxx",
'body' => "Hi $name. $text"
)
);
// Display a confirmation message on the screen
echo "Sent message to $name <br>";
}
此代码是什么是定制的。
它回应成功。
但如果isn't有效一些,该过程将像一个错误信息停止:
Sent message to David
Sent message to Elsa
Sent message to Adam
Failure notice: the number is not a valid phone number...
,这里的循环中断..
什么我倒是喜欢的是环打印出失败消息,但仍然发送失败后出现的数组中的一个。而不会打破循环。
错误消息必须来自API dist文件?
因为我无法瑟任何错误在我定制的PHP文件处理..
它是一个例外呢?在这种情况下,围绕SMS创建呼叫使用try catch并相应处理。 –
@JonStirling,打我吧。 –