用php发送手机短信
2013-07-25 12:46
218 查看
/**
* 手机短信发送(这里是以凌凯的为例,各服务商提供的例程可能各有不同)
* @param string $phone_num
* @param string $message_content
* @return boolean
*/
function shortmessage_send($phone_num,$message_content){
//短信接口用户名 $uid
$uid = 'XXX';
//短信接口密码 $passwd
$passwd = 'XXX';
//发送到的目标手机号码 $telphone
$telphone = trim($phone_num);
//转换编码
$message=mb_convert_encoding(trim($message_content), "GB2312", "UTF-8");
if(!preg_match("/^1[3|4|5|8][0-9]\d{8}$/", $telphone) || empty($message) )
return false;
$gateway = "http://mb345.com:999/ws/batchSend.aspx?CorpID={$uid}&Pwd={$passwd}&Mobile={$telphone}&Content={$message}&Cell=&SendTime=";
$result = file_get_contents($gateway);
if($result == 0 || $result == 1)
return true;
else
return false;
}
注意:1.本地编码与服务商服务器的编码不同会乱码而导致发送不出
2.内容主题空格也可能导致乱码
3.服务商的一些规定,如:其关键字、不能一天内发送相同的短信也可致错
* 手机短信发送(这里是以凌凯的为例,各服务商提供的例程可能各有不同)
* @param string $phone_num
* @param string $message_content
* @return boolean
*/
function shortmessage_send($phone_num,$message_content){
//短信接口用户名 $uid
$uid = 'XXX';
//短信接口密码 $passwd
$passwd = 'XXX';
//发送到的目标手机号码 $telphone
$telphone = trim($phone_num);
//转换编码
$message=mb_convert_encoding(trim($message_content), "GB2312", "UTF-8");
if(!preg_match("/^1[3|4|5|8][0-9]\d{8}$/", $telphone) || empty($message) )
return false;
$gateway = "http://mb345.com:999/ws/batchSend.aspx?CorpID={$uid}&Pwd={$passwd}&Mobile={$telphone}&Content={$message}&Cell=&SendTime=";
$result = file_get_contents($gateway);
if($result == 0 || $result == 1)
return true;
else
return false;
}
注意:1.本地编码与服务商服务器的编码不同会乱码而导致发送不出
2.内容主题空格也可能导致乱码
3.服务商的一些规定,如:其关键字、不能一天内发送相同的短信也可致错
相关文章推荐
- php 发送手机短信
- 手机验证码平台,怎么发送手机验证码,php开发手机验证码短信接口功能
- 通过ICQ网关发送手机短信的PHP源程序
- php使用ICQ网关发送手机短信
- php 发送手机短信
- 通过ICQ网关发送手机短信的PHP源程序
- php手机短信接口发送验证码
- PHP实现 手机发送短信的程序
- 容联云通讯实现php的手机发送短信验证
- PHP 手机短信发送验证码
- 飞信PHP接口|飞信PHP API免费发送手机短信接口,thinkphp发送单条函数
- 通过ICQ网关发送手机短信的PHP源程序
- 服务器开机自动发送短信到手机
- PHP下用redis队列发送短信PHP CLI代码
- JAVA发送手机短信,httpclient短信发送接口示例(java)
- php版https证书过期时间检测/并发送短信给相关技术人员(crontab定时脚本版)
- 【转】android 手机发送短信,震动,播放默认铃声
- 基于SMS短信平台给手机发送短信
- php短信接口(发到手机上)