SailorJ SailorJ - 3 months ago 16
PHP Question

Twilio <say> being cut off by PHP sleep()

I have a Twilio IVR that asks a caller for their account number. After the caller enters their account number at voice.xml the input is sent to begin.php. I am trying to send the caller back to voice.xml if their account number is not in my database. The code below will send them back as expected but they are redirected before I can inform them that their number was incorrect. I tried adding PHP

but this seems to cut off the Twilio
tag as well...

if(mysql_num_rows($result) == 0){
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<Response><Say>Sorry your account number was not found.</Say></Response>";
header('Location: voice.xml');


You shouldn't handle redirection in your script. use Twiml <Redirect> verb instead.

<?xml version="1.0" encoding="UTF-8"?>
    <Say>Sorry your account number was not found.</Say>

This way, Twilio will announce the message to the caller, then redirects him to voice.xml.

Hope it helps.