简体   繁体   English

如何在 Nexmo 代码中设置我的 php 变量

[英]How can I set my php variables in Nexmo code

I an setting up a website to send SMS automatically by API key Nexmo.我正在建立一个网站,通过 API 密钥 Nexmo 自动发送短信。 But whene I add my variables into the Nexmo code, this one not work.但是当我将我的变量添加到 Nexmo 代码中时,这个不起作用。 How can I add my variables please?请问如何添加我的变量?

I added my php variables to the Nexmo SMS default code but no result, but whene I trayed there code the stuff work fine我将我的 php 变量添加到 Nexmo SMS 默认代码中,但没有结果,但是当我在那里输入代码时,这些东西工作正常

my file phone.php , with $row["phone_number"]=212981416807 at this exemple我的文件 phone.php ,在这个例子中有 $row["phone_number"]=212981416807

$text1 = "Hello";
$text2 = " this is my company";
$MyNexmoID_Account = "3896321";
$MyNexmoAPI_Key = "yhg784frds78jkim";
$to = $row["phone_number"];
$from = "my company";
$text = "$text1 $text2";


// Code to Send SMS with Code Recharge ------
    require_once "vendor/autoload.php";
        //composer require nexmo/client;
    $basic  = new \Nexmo\Client\Credentials\Basic('$MyNexmoID_Account', '$MyNexmoAPI_Key');
    $client = new \Nexmo\Client($basic);

    $message = $client->message()->send([
    'to' => '$to',
    'from' => '$from',
    'text' => '$text'
    ]);
    if ($message && $client && $basic){echo " Recharge Code Sent Correctlly.";}else{echo "Failed! Recharge Code Not Sent.";}
// End Code to Send SMS with Code Recharge -----

This is default Nexmo code:这是默认的 Nexmo 代码:

    require_once "vendor/autoload.php";
        //composer require nexmo/client;
    $basic  = new \Nexmo\Client\Credentials\Basic('3896321', 'yhg784frds78jkim');
    $client = new \Nexmo\Client($basic);

    $message = $client->message()->send([
    'to' => '212981416807',
    'from' => 'Nexmo',
    'text' => 'Hello Nexmo'
    ]);

You don't need to quote variables.您不需要引用变量。 Try this:尝试这个:

$message = $client->message()->send([
'to' => $to,
'from' => $from,
'text' => $text
]);

Not sure if you have corrected this but do check your country code, I had a similar error with variable (also do listen to Michael Heap), where the hard code for the US phone number was 19091234567 and my database number was 9091234567. Unlike Twilio, Nexmo needs the country code.不确定您是否已更正此问题,但请检查您的国家/地区代码,我有一个类似的变量错误(也请听 Michael Heap),其中美国电话号码的硬代码是 19091234567,我的数据库号码是 9091234567。与 Twilio 不同, Nexmo 需要国家代码。 Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM