I am trying to deploy a sms application which is written in PHP and I am deploying it on Heroku and using Twilio to send messages. When someone sends a message on my Twilio number, this app will send an appropriate reply to that message. I am facing a problem with switch statement in this app. I am new to coding in PHP and I am unable to get this to work. I am pasting my code below. Please help me fix it. Thank you in advance.
<?php
session_start();
header("content-type: text/xml");
switch ($answer) {
case 'headache' : {
print('OTC Crocin may help!');
break;
case 'stomachache' : {
print('OTC Tylenol may help!');
break;
case 'cough' : {
print('OTC Robitussin Cough may help!');
break;
case 'cold' : {
print('OTC Aspirin may help!');
break;
case 'vomiting' : {
print('OTC Pepto-Bismol may help!');
break;
case 'headache doctor' : {
print('Dr. Lorem Ipsum - Here is the address! Call at +1 xxx xxx xxxx');
break;
case 'stomachache doctor' : {
print('Dr. Lorem Ipsum - Here is the address! Call at +1 xxx xxx xxxx');
break;
case 'cough doctor' : {
print('Dr. Lorem Ipsum - Here is the address! Call at +1 xxx xxx xxxx');
break;
case 'cold doctor' : {
print('Dr. Lorem Ipsum - Here is the address! Call at +1 xxx xxx xxxx');
break;
case 'vomiting doctor' : {
print('Dr. Lorem Ipsum - Here is the address! Call at +1 xxx xxx xxxx');
break;
}
$from = $_POST['From'];
$answer = $_POST['Body'];
$reply = array();
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Sms>
<?php
if(is_array($reply)){
foreach($reply as $key => $value){
echo $value;
}
}
else{
echo $reply;
}
?>
</Sms>
</Response>
答案 0 :(得分:0)
Twilio开发者传道者在这里。
您正在回复收到的短信,但是您使用的是<Sms>
TwiML verb。 <Sms>
仅用于在语音通话期间发送短信。
相反,您希望使用用于回复SMS消息的<Message>
TwiML动词。因此,代码的最后一部分应如下所示:
<Response>
<Message>
<?php
if(is_array($reply)){
foreach($reply as $key => $value){
echo $value;
}
}
else{
echo $reply;
}
?>
</Message>
</Response>