【问题标题】:Integrate Twilio PHP in Wordpress在 Wordpress 中集成 Twilio PHP
【发布时间】:2018-05-28 18:16:10
【问题描述】:

我的 Twilio PHP,我的 HTML 表单在本地运行良好,但是当我将文件放入我的 Wordpress 主题文件夹并尝试通过在标签之前的 header.php 中添加这行代码来包含 PHP 文件时:

<?php include 'sendnotifications.php';?>

我的页面上有这个错误:

Warning: include(): Failed opening 'sendnotifications.php' for
 inclusion (include_path='.:/usr/lib/php7.1') in 
/htdocs/clickandbuilds/MyWebsite/wp-content/themes/Divi/header.php on line 3

编辑:

它正在工作,我没有将文件放在好的文件夹中。现在我有另一个问题,它只适用于预定义的电话号码:

$sid = 'MySID';
$token = 'MyToken';
$client = new Client($sid, $token);

    // Use the client to do fun stuff like send text messages!
    $client->messages->create(
        // the number you'd like to send the message to
       'MyPersonal number',  
        array(
            // A Twilio phone number you purchased at twilio.com/console
            'from' => 'MyTwilioNumber',
            // the body of the text message you'd like to send
            'body' => 'Hey Jenny! Good luck on the bar exam!'

但是当我尝试从页面上的表单中获取自定义电话号码时:

$sid = 'MySID';
$token = 'MyToken';
$client = new Client($sid, $token);
$phone=$_POST["phone"];

            // Use the client to do fun stuff like send text messages!
            $client->messages->create(
                // the number you'd like to send the message to
               $phone,  
                array(
                    // A Twilio phone number you purchased at twilio.com/console
                    'from' => 'MyTwilioNumber',
                    // the body of the text message you'd like to send
                    'body' => 'Hey Jenny! Good luck on the bar exam!'

我有这个错误

Fatal error: Uncaught Twilio\Exceptions\RestException: [HTTP 400] Unable to create record: A 'To' phone number is required. in /homepages/10/d659162273/htdocs/clickandbuilds/MyWebsite/wp-content/themes/Divi/vendor/twilio/sdk/Twilio/Version.php:85 Stack trace: #0 /homepages/10/d659162273/htdocs/clickandbuilds/MyWebsite/wp-content/themes/Divi/vendor/twilio/sdk/Twilio/Version.php(219): Twilio\Version->exception(Object(Twilio\Http\Response), 'Unable to creat...') #1 /homepages/10/d659162273/htdocs/clickandbuilds/MyWebsite/wp-content/themes/Divi/vendor/twilio/sdk/Twilio/Rest/Api/V2010/Account/MessageList.php(69): Twilio\Version->create('POST', '/Accounts/AC8ec...', Array, Array) #2 /homepages/10/d659162273/htdocs/clickandbuilds/MyWebsite/wp-content/themes/Divi/sendnotifications.php(20): Twilio\Rest\Api\V2010\Account\MessageList->create(NULL, Object(Twilio\Values)) #3 /homepages/10/d659162273/htdocs/clickandbuilds/MyWebsite/wp-content/themes/Divi/header.php(3): include('/homepag in /homepages/10/d659162273/htdocs/clickandbuilds/MyWebsite/wp-content/themes/Divi/vendor/twilio/sdk/Twilio/Version.php on line 85

我有点迷茫

【问题讨论】:

  • 您确定正确地从 POST 请求的正文中检索到电话号码吗?你请求电话号码的页面上&lt;input&gt;的name属性是什么?

标签: php wordpress twilio twilio-api


【解决方案1】:

您应该为 wordpress 安装 twilio 插件以使其与 wordpress 一起使用。

这是download 的插件链接。之后,您将不得不编写代码。

在下面的链接上关注 twilio for wordpress 的官方教程:

https://www.twilio.com/blog/2017/08/send-sms-wordpress-php-plugin.html

【讨论】:

  • 谢谢,我试试
  • 它在 twilio 中的权限问题,您必须登录到您的 twilio 帐户并导航到语音通话(地理权限)设置并检查您拨打电话的国家/地区,然后保存。跨度>
猜你喜欢
  • 1970-01-01
  • 2016-04-03
  • 2018-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多