PHP TP5 实现短信发送 此API为短信宝
1.编写前台页面
<form action="phoneDo" method="post"> <input type="text" name="phone"> <button type="submit">发送</button> </form>
2.后台接收并发送
public function phoneDo(){ //接受前台表单传来的电话号 $phone=input('phone'); //生成四位随机数 $num=rand(1000,9999); //编写短信内容 $content="【龍】你的验证码是:".$num.",3分钟内有效!"; $statusStr = array( "0" => "短信发送成功", "-1" => "参数不全", "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!", "30" => "密码错误", "40" => "账号不存在", "41" => "余额不足", "42" => "帐户已过期", "43" => "IP地址限制", "50" => "内容含有敏感词" ); $smsapi = "http://api.smsbao.com/"; $user = "****"; //短信平台帐号 $pass = md5("****"); //短信平台密码 $content=$content;//要发送的短信内容 $phone = $phone;//要发送短信的手机号码 $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content); $result =file_get_contents($sendurl) ; echo $statusStr[$result]; }
3.短信平台帐号,短信平台密码,为你注册短信宝时的账号密码
短信宝网址:http://www.smsbao.com/