I have the following script for getting a response from the Twilio number when a sms is sent to it. However, when I run my script, it doesn't work for all keywords. I am not sure why? It runs for '1' and 'hello' as keywords but that's it.
Code:
<?php
require __DIR__ . '/twilio-php-master/Twilio/autoload.php';
$from = $_REQUEST['From'];
$body = $_REQUEST['Body'];
$result = preg_replace("/[^A-Za-z0-9]/u", " ", $body);
$result = trim($result);
$result = strtolower($result);
print_r($result);
/*Match the ‘Body’ field with index of keywords */
if( $result == '1' ){
$response = 'Hi, We will be in touch with you!';
}else if( $result == 'hello' ){
$response = 'Thank you!';
}else if( $result == 'Support' ){
$response = 'Thank you! An agent will be in touch shortly.';
}else if( $result == 'LINK' ){
$response = 'https://google.com';
}
// header('content-type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?> <Response> <Message><?php echo $response; ?></Message> </Response>
Comment