Forum Moderators: coopster

Message Too Old, No Replies

open email from script

         

cantona

7:50 am on Sep 17, 2008 (gmt 0)

10+ Year Member



Hi

I've got a plain old email link on a web page. But I now want to record how many people click on it.

To do this I'll need to point the link to a PHP script to do the hit recording. But then I still want the email link to work as normal, and open up the users default mail client.

How can I do that last bit? Is there some header() code I need to add?

Thanks

penders

8:35 am on Sep 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My first thought would be to add an onclick event to your anchor that fires off an XMLHttpRequest to your server-side PHP script to update your click count. Allow the mailto: link to be followed in the usual way.

cantona

3:20 pm on Sep 25, 2008 (gmt 0)

10+ Year Member



thanks penders. i've tried this out, but im not quite there yet. do you know what im doing wrong?

my link (444 is the Id of the page im emailing about):


<a href="mailto:cantona@domain.com" onclick="apply('444');></a>

my javascript file:


// ajax set up
function getHTTPObject()
{
if (typeof XMLHttpRequest != 'undefined')
{
return new XMLHttpRequest();
}
try
{
return new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{}
}
return false;
}

function apply(id) {
var myurl = "http://www.domain.com/apply_ping.php";
http.open("GET", myurl + "?id=" + escape(id), true);
http.onreadystatechange = useHttpResponse;
http.send(null);
}

function useHttpResponse() {
if (http.readyState == 4) {
var textout = http.responseText;
document.write.textout;
}

}

and my php file:


<?php
$id = $_GET['id'];
# add $id to db
# thats it, the end

so i just want to add a row the DB with the ID in. the email click should trigger this.

any ideas? im totally new to ajax :/