在Wordpress中集成Twilio PHP

时间:2018-05-28 09:33:34

标签: php wordpress twilio twilio-api

我的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

我有点失落

1 个答案:

答案 0 :(得分:1)

你应该安装wordpress的twilio插件才能使用wordpress。

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

在以下链接上按照twilio的官方教程进行wordpress:

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