如何通过短信发送激活码
有没有PHP脚本可以发送短信?我想在用户的手机上发送激活码。
Is there any PHP script to send SMS. I wan to send activation code on user's mobile phone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有没有PHP脚本可以发送短信?我想在用户的手机上发送激活码。
Is there any PHP script to send SMS. I wan to send activation code on user's mobile phone.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
这是一个 PHP 中的 SMS 验证示例,使用Twilio(完全披露,我为 Twilio 工作)。
Here's an SMS verification example in PHP using Twilio (full disclosure, I work for Twilio).
您将需要一个短信网关。他们中的很多人都会通过短信将消息发送到电子邮件,因此您只需使用
mail()
函数即可。这看起来是一堆不错的链接。
You will need a SMS gateway. A lot of them will send messages sent to an email on via SMS, so you can just use the
mail()
function.This looks like a good bunch of links.
您需要从服务器到蜂窝网络建立某种连接(例如手机或 GSM 调制解调器)才能直接发送短信。
但如果您愿意通过第三方服务,还有很多选择。查看这些问题以获取一些提示:
我打赌这些问题的答案中列出的一些服务也有可用的示例 PHP 脚本。
You need to have a connection of some sort (for example a cell phone or a GSM modem) from your server to the cell network to directly send text messages.
But there are a lot of alternatives if you're willing to go through a third party service. Look at these question for some tips:
I bet some of the services listed in the answers of those questions also have example PHP-scripts available.
根据您的蜂窝网络提供商的不同,最简单的选择是使用 WWW 或电子邮件 SMS 网关 - 如果他们提供的话。没有两个提供商拥有相同的 API,您必须进行 RTM 并进行调整。
否则,您将不得不使用 GSM 调制解调器 - 购买一个具有详细记录的 AT 命令集的调制解调器。您可以使用扩展 AT 命令集通过串行端口(普通 RS232 或通过 USB 线路模拟)进行通信。您必须与调制解调器对话 - 向其传递 PIN(发送
AT+CPIN="0000"
或其他内容),然后使用类似的命令发送短信。在购买调制解调器之前一定要查找文档,因为有许多“消费者”调制解调器需要专有软件才能使用,并且不导出任何用于 SMS 等的 API。我很确定大多数 Wavecom 和 Sagem 调制解调器都是“开放的”,OTOH 避免使用像火一样的“零安装驱动程序”华为 - 它们识别为内部带有自动播放磁盘的 CD 驱动器,并且自动播放会安装驱动程序,发送特殊命令来切换调制解调器从“CD 驱动器”模式进入“调制解调器”模式...需要相当多的工作来自己完成。
有一个 PHP 模块可以使用串行端口,只需配置调制解调器并将脚本指向正确的端口(/dev/ttyUSB0、COM1 等),但我认为您必须自己处理 AT 命令集层。
Depending on your cellular network provider, the easiest option would be using a WWW or email SMS gateway - if they provide any. No two providers have the same API, you'll have to RTM and adapt.
Otherwise, you're stuck with a GSM modem - grab one with a well docummented AT command set. You communicate over a serial port (either plain RS232 or emulated over USB line), using extended AT command set. You'll have to converse with the modem - pass it the PIN, (send
AT+CPIN="0000"
or whatever), then send the SMS with some similar command.Definitely look for docs before purchase of the modem, as there are many "consumer" modems that require proprietary software to use and don't export any API for SMS and the likes. I'm pretty sure most Wavecom and Sagem modems are "open", OTOH avoid Huaweii with "zero-installation drivers" like fire - they identify as CD-Drive with autoplaying disk inside, and the autoplay installs driver that sends special command to switch the modem into "modem" mode from "CD drive" mode... takes quite a bit of work to do it yourself.
There is a PHP module to use serial port, just configure the modem and point your script at the right port ( /dev/ttyUSB0, COM1 etc) but I think you'll have to handle the AT commands set layer yourself.