【问题标题】:Send Message to phone using Codeigniter使用 Codeigniter 向手机发送消息
【发布时间】:2016-07-26 11:21:24
【问题描述】:

我有一个 codeigniter 基础网站,我尝试使用 Codeigniter 框架通过电话和电子邮件忘记密码来更改密码通知。电子邮件已经在工作,但我不知道如何使用 codeigniter 向电话发送消息??

我的一位朋友告诉我,使用 Curl 功能向手机发送消息。但我之前对 CURL 功能没有任何想法,所以我在谷歌上搜索但我不知道如何做到这一点。

您能否就如何使用 codeigniter 向手机发送消息提供适当的建议。

我们将不胜感激任何形式的帮助。

提前致谢。

【问题讨论】:

  • 那是不可能的。您需要找到提供 PHP API 的主机。你不能只从你的 php 本身发送一条短信,没有任何东西。
  • 我推荐 twilio
  • 是的。正如所有人所暗示的那样,Twilio 是最好的
  • @StevenDropper 有没有简单的 PHP 函数用于向手机发送消息?

标签: php codeigniter sms sendmessage sms-gateway


【解决方案1】:

这是一个简单的代码点火器助手,您需要将其保存为 helpers/sendsms_helper.php

function sendsms($number, $message_body, $return = '0') {

$sender = 'SEDEMO'; // Can be customized

$smsGatewayUrl = 'http://springedge.com';

$apikey = '62q3xxxxxxxxxxxxxxxxxxxxxx'; // Need to change

$textmessage = urlencode($textmessage);

$api_element = '/api/web/send/';

$api_params = $api_element.'?apikey='.$apikey.'&sender='.$sender.'&to='.$number.'&message='.$textmessage;
$smsgatewaydata = $smsGatewayUrl.$api_params;

$url = $smsgatewaydata;

$ch = curl_init();

curl_setopt($ch, CURLOPT_POST, false);

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch);

curl_close($ch);

if(!$output){ $output = file_get_contents($smsgatewaydata); }

if($return == '1'){ return $output; }else{ echo "Sent"; }

}

使用方法: 您可以在项目中的任何位置使用以下功能发送短信: 调用 sendms 函数 例如。 sendsms( '919918xxxxxx', 'test message' );

请确保将 sendms 助手加载为$this->load->helper('sendsms_helper');

【讨论】:

【解决方案2】:

有许多公司提供相同的 api。我使用twilio 有一段时间了,觉得它很可靠。相同的代码可以是

<?php
    require "Services/Twilio.php";
    $AccountSid = "";  //get from twilio
    $AuthToken = "";   //get from twilio
    $client = new Services_Twilio($AccountSid, $AuthToken);
    $sms = $client->account->messages->sendMessage(
        $tNumber, // Your twilio number 
        $number, // Number you want to send to
        $message // Message you want to sms
    );

希望这会有所帮助。同样,您还可以查看许多其他服务

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-09
    • 1970-01-01
    相关资源
    最近更新 更多