PHP实现在线发短信,需要借助第三方API,以下代码就是调用了TextMagic API来实现发送短信的功能:
view sourceprint?01
02//引入TextMagic PHP库文件
03require('textmagic-sms-api-php/TextMagicAPI.php');
04$username = 'myusername';
05$password = 'mypassword';
06$router = new TextMagicAPI(array(
07 'username' => $username,
08 'password' => $password
09));
10//发送一条信息到'222-345-5678'
11$result = $router->send('Wake up!', array(2223455678), true);
12//结果(官方资料): Array ( [messages] => Array ( [19896128] => 9991234567 ) [sent_text] => Wake up! [parts_count] => 1 )
13?>
若没有TextMagic API类库的可在这里下载:TextMagic-SMS-API PHP发送短信模块类