2017-09-01 88 views
0

恭维。用php代码在线发送短信

我是新来的PHP,但我一直在尝试在我的网站上创建一个短信平台/通知,以补充已经创建的通讯通知,但我迷失在如何初始化多个变量作为一个单位在我的工作php代码。步骤如下:

//i favour if...elseif over the switch method 
//to declare the gateways variables 

//step one. declaring gateways variables 

$us_ca = array ('@txt.att.net', '@smscellular.com', '@more_gateways'); 
$nig = array ('@smsairtel.ng.com', '@more_gateways'); 
$gha = array ('@txt.mtn.com.gh', '@more_gateways'); 
.................................................. 

//note that the gateways are not correct but only cited as samples. 
// i use more_gateways to represent others i couldn't write 
// because of time and space 
//step two. where the sms gets delivered. 

if zip_code == '+1' { 
    email = '$telephone$us_ca', '$zip_code$telephone$us_ca'; //telephone 
    var for user's telephone, i create a second because some gateways 
    requires the country zip code. 
} elseif zip_code == '+234'{ 
    email = '$telephone$nig', '$zip_code$telephone$nig';     
} elseif zip_code == '+233'{ 
    email = '$telephone$gha', '$zip_code$telephone$gha';     
} 
........................................................ 
//note that i am targeting almost 90 countries. 

现在我想知道的是,如果它的好宣布阵列VAR网关如上步骤之一,如果完成初始化多个变种我在第二个步骤”不是个做的方式不好。

请注意,每个短信同时发送到阵列中的所有网关,因为每个单独的电话号码对于在特定国家/地区提交的用户来说是唯一的,所以短信只能发送给用户即使它首先到达所有的网关。

在此先感谢。在简单的PHP函数

+0

你不能直接从PHP发送短信。您可以尝试twilio或smsgh –

+0

我想我已经在网上看过帖子,证实可以通过php发送短信。做一个彻底的在线检查,看看你自己;事实上,我通过我的研究得到了方法,但是据说一次可以通过电子邮件发送一个网关(或一组网关),但我想知道在这种情况下是否可以添加var。或如下所示: 如果zip_code =='+1'{ email ='$ zip_code。= $ telephone。= $ us_ca' } 感谢您的回复。 – test

+0

检查了这一点。 https://code.tutsplus.com/tutorials/how-to-send-text-messages-with-php--net-17693 –

回答

3

电话短信RESTAPI发送短信:

function CURLsendsms($number, $message_body){ 
$api_params = $api_element.'?apikey='.$apikey.'&sender='.$sender.'&to='.$mobileno.'&message='.$textmessage; 
$smsGatewayUrl = "http://springedge.com"; 
$smsgatewaydata = $smsGatewayUrl.$api_params; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_POST, false); 
curl_setopt($ch, CURLOPT_URL, smsgatewaydata); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$output = curl_exec($ch); 
curl_close($ch); 
// Use file get contents when CURL is not installed on server. 
if(!$output){ 
$output = file_get_contents($smsgatewaydata); 
} 
} 

你也可以使用PHP类发送短信 http://www.phpclasses.org/package/9522-PHP-Send-SMS-messages-with-Spring-Edge-API.html

有两个文件在上面的类:

  • sendingms.php - 调用短信网关的类文件restAPI
  • test.php - 用于测试短信功能的示例文件。

本课程使用spring edge短信网关提供程序API,您可以根据需要为其他任何短信提供程序定制RestAPI url和params。

+0

感谢您的回复,但问题是我不想使用付费服务该平台,如果我没有第三方应用程序或网站可以做的更好。似乎你提供的短信网关网站是一个付费系统? – test

+0

@test没有免费的短信服务可用,因为每个短信是收费的运营商。你可以去最小的包 – BSB