您的位置:首页 > 编程语言 > PHP开发

用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.服务商的一些规定,如:其关键字、不能一天内发送相同的短信也可致错
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: