Forwarding Recordings to your email

It is possible to forward voicemail or other recordings made with Twilio's <Record> verb to your email inbox.

The following TwiML will give Twilio instructions to make a recording. Once the recording is made, Twilio will make a request to "mail.php" containing both the parameters from the Twilio Request and the <Record> request parameters:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Record action="mail.php" />
</Response>

This PHP code parses the incoming request from Twilio, then sends an email to the address you specify:

<?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.

/**
* This section actually sends the email.
*/

/* Your email address. */
$to = "your-email@example.com";
$subject = "Message from {$_REQUEST['From']}";
$message = "You have received a message from {$_REQUEST['From']}.";
$message .= "To listen to this message, please visit this URL: {$_REQUEST['RecordingUrl']}";
$headers = "From: webmaster@example.com"; // Who should it come from?
mail($to, $subject, $message, $headers);

Any of the parameters which are part of the Twilio Request can also be used.

Have more questions? Submit a request
Powered by Zendesk