[Updated] How to: Send email when video is played
Posted: Wed May 02, 2012 7:39 pm
EDIT (10/15/2012): I've updated the code a little bit, it should work better than before. This is test on SubSonic ver. 4.7
This tutorial will show you how to modify SubSonic to send an email when a video file is played along with the user and IP address. This is my first one so be nice if there are any errors.
Currently this doesn't work in IE9, if someone knows why I would like to hear.
Edit playAddDownload.jsp (yours may be different but here is mine) - located in C:\subsonic\jetty\2583\webapp\WEB-INF\jsp
Add the following code to the top of the file
Then in the same file look for this chuck of code, around line ~54
Make it look like this
Now hopefully you have a hosting provider that supports .php or you could use your local machine. Create a .php file called sendemail.php and put it on your hosting account like in the above code. In this .php file you will want to put the following code.
This tutorial will show you how to modify SubSonic to send an email when a video file is played along with the user and IP address. This is my first one so be nice if there are any errors.
Currently this doesn't work in IE9, if someone knows why I would like to hear.
Edit playAddDownload.jsp (yours may be different but here is mine) - located in C:\subsonic\jetty\2583\webapp\WEB-INF\jsp
Add the following code to the top of the file
- Code: Select all
<script>
function sendMail(video, user) {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {// IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "http://www.yourdomain.com/somedirectory/sendemail.php?video="+video+"&user="+user+'&ip=<%= request.getHeader("X-Real-IP") %>', false); // Use this if using a reverse proxy
xmlhttp.open("GET", "http://www.yourdomain.com/somedirectory/sendemail.php?video="+video+"&user="+user+"&ip=<%= request.getRemoteAddr()) %>", false); // Use this if using a NAT on your firewall
xmlhttp.send();
}
</script>
Then in the same file look for this chuck of code, around line ~54
- Code: Select all
<a href="${videoUrl}" target="main">
Make it look like this
- Code: Select all
<a href="${videoUrl}" target="main" onclick="sendMail(parentElement.parentElement.getElementsByTagName('span')[2].attributes['title'].value, '${model.user.username}')">
Now hopefully you have a hosting provider that supports .php or you could use your local machine. Create a .php file called sendemail.php and put it on your hosting account like in the above code. In this .php file you will want to put the following code.
- Code: Select all
<?php
$videoplaying = $_GET['video'];
$username = $_GET['user'];
$ip = $_GET['ip'];
$to = "youremail@email.com";
$subject = "Video Streaming";
$message = $username . " has just started watching " . $videoplaying . " from IP Address: " . $ip;
$from = "subsonic@yourdomainname.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>