Reputation: 21
I'm using the twimlbin service to test a simple bit of Twilio xml:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>This call may be recorded for quality purposes</Say>
<Dial record="true" action="http://testmyapp.ca/sendmail.php" method="GET">
555-404-3200
</Dial>
</Response>
At the action url I receive the url of the recording and the duration and send an email to myself. All goes well, the email is sent, but the voice on the phone says an application error has occurred. The error is a 12100 error (http://www.twilio.com/docs/errors/12100). From the debugger service I get "Error on line 1 of document : Premature end of file. Please ensure that the response body is a valid XML document." I'm not doing anything but sending an email from my php file - should I be returning a response to Twilio here from my php file? I've commented out any output from sendmail.php I receive the email with the GET parameters I expect but the voice still says an application error has occurred. Any help much appreciated.
Upvotes: 1
Views: 1016
Reputation: 41
I had this same problem and here is how I solved it. Just add this header to your mail.php file:
<?php
/**
* This section ensures that Twilio gets a response.
*/
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<Response></Response>'; //Place the desired response (if any) here.
That's it. No need to place a response. After that header, comes the section that sends the email.
I read somewhere that you need a Hangup response. No need for that. Also, I should mention my mail.php file ended with a line like this
echo '</Response>';
I just deleted that line. It was unnecessary.
I hope this helps anybody else running into the same problem.
Upvotes: 4
Reputation: 3434
It sounds like when Twilio makes a request to your action URL, your response doesn't contain any TwiML. If the call is to continue, you should add some Twiml - possibly just a <Hangup>
, or even an empty <Response/>
should do. See the documentation for <Dial>
on Twilio's website.
Upvotes: 4