Record message to mail
<?xml version = "1.0" ?>
<vxml version = "2.1" xmlns="http://www.w3.org/2001/vxml" xml:lang="en-US">
<property name="fetchtimeout" value="60s" />
<property name="fetchtimeout" value="30s" />
<form>
<var name="caller" expr="session.connection.remote.uri"/>
<catch event="connection.disconnect.hangup">
<submit namelist="caller record" method="post" enctype="multipart/form-data" next="send.php" />
</catch>
<noinput>
<reprompt/>
</noinput>
<nomatch>
<reprompt/>
</nomatch>
<record name="record" dtmfterm="false" maxtime="120s" type="audio/x-wav" beep="true">
<prompt bargein="false">
<audio src="audio/greeting.wav"/>
</prompt>
</record>
<block>
<submit namelist="caller record" method="post" enctype="multipart/form-data" next="send.php" />
</block>
</form>
</vxml>
<?php
require("include/class.phpmailer.php");
$caller=$_POST['caller'];
$called=$_POST['called'];
$number=$_POST['number'];
//if (isset($_FILES['record']))
{
//if (file_exists($_FILES['record']['tmp_name']) && is_uploaded_file($_FILES['record']['tmp_name']) )
$infile=$_FILES['record']['tmp_name'];
// Allow the rigths for Apache if you want to keep the recording on the server
$outfile="/var/www/vxml/messagebox/files/".$caller.".mp3";
@unlink($outfile);
system("ffmpeg -i $infile -ab 8k $outfile");
if (1)
{
// Instantiate your new class
$mail = new PHPMailer();
//$mail->SMTPDebug =true;
// Now you only need to add the necessary stuff
$mail->IsSMTP();
//$mail->SMTPAuth = true; // enable SMTP authentication
//$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
//$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
//$mail->Port = 465; // set the SMTP port for the GMAIL server
//$mail->Username = "name@gmail.com"; // GMAIL username
//$mail->Password = "xxxxxx"; // GMAIL password
//$mail->AddReplyTo("name@gmail.com", "First Last");
//$mail->Host = "smtp.free.fr"; // sets GMAIL as the SMTP server
//$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->From = "marketing@domain.com";
$mail->FromName = "Ulex.fr";
$mail->AddAddress("borja.sixto@domain.com", "Borja");
$mail->AddAddress("marketing@ulex.fr", "Ulex.fr");
$mail->Subject = "Message : from ".$caller." to Ulex.fr";
$mail->Body = "A file is attached ("."mp3".")\n";
$mail->AddAttachment($outfile, $caller.".mp3");
if(!$mail->Send())
{
readfile("error.vxml");
exit;
}
}
}
readfile("goodbye.vxml");
?>
The VoiceXML browser will record a message and post it with multipart encoding. The PHP script get the recording, convert it locally to MP3 and send an email with the audio file attached.
Download : record.vxml send.php