我将网站设置为通过API密钥Nexmo自动发送短信。但是,当我将变量添加到Nexmo代码中时,此代码将无法工作。我如何添加变量?
我将php变量添加到Nexmo SMS默认代码中,但是没有结果,但是当我在那儿放上代码时,这些东西就可以正常工作了
我的文件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 -----
这是默认的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'
]);
答案 0 :(得分:0)
您不需要引用变量。试试这个:
$message = $client->message()->send([
'to' => $to,
'from' => $from,
'text' => $text
]);
答案 1 :(得分:0)
不确定是否已纠正此问题,但确实检查了您的国家/地区代码,我在变量中也遇到了类似的错误(也收听Michael Heap),其中美国电话的硬代码为19091234567,数据库编号为9091234567与Twilio不同,Nexmo需要国家代码。希望对您有所帮助。