Forum Moderators: coopster

Message Too Old, No Replies

Email Tracking/Dynamic Emails?

how to execute php in an email

         

kkonline

5:38 am on Aug 21, 2007 (gmt 0)

10+ Year Member



Is there any way of email tracking or sending dynamic emails?

What i mean is > if i want to send a php code in an email such
that whenever the user opens the email he sees the CURRENT DATE
AND TIME.

Or When i post a newsletter, i should get to know the email id
if not then atleast the ip addresses and the number of people
till now who have opened the mail. That means whenever someone
opens an email, the counter should be incremented and displayed
on the email itself or on my server

I want to send php function/code in the email which executes
as it does on my server and not just display the code as text part of the mail

If I have $value=6++;

then if i write echo $value;
It should print 6 on the email for the first time and then increment
and show 7, 8... whenever that mail is opened next..

venelin13

5:57 am on Aug 21, 2007 (gmt 0)

10+ Year Member



You can not execute a PHP code inside an email message.

Well, there are several ways to do the counter functionality. All of them will work only of the email message is HTML formated.

1. Add an image tracker, such as:


<img src="http://www.example.com/tracker.php?email_id=NUMBER" />

Everytime this email message is opened, the tracker.php script at your server will be executed. You may play with this and add extra functionality, for example - to prevent couting of opening the same message from the same recipient more than once.

2. Add an iframe at your code. The iframe source can be loaded again from your server. I am not quite sure if this will working! To display the today date, you can allways add some JavaScript code to your HTML formated message.

dreamcatcher

6:46 am on Aug 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can not execute a PHP code inside an email message.

Actually, you can if its html formatted and you use some kind of pixel tracking.

dc

kkonline

6:53 am on Aug 21, 2007 (gmt 0)

10+ Year Member



Dear venelin13 and dreamcatcher,
I got the point that if the email is html formatted then i can do the above thing. But not getting how to implement tracker.php?email=number part. can you give more details or better share a code similar to it's functionality. I want to track the email ids who have read the newsletter.

Why do you need that id=number part what's it's use?

kkonline

8:50 am on Aug 21, 2007 (gmt 0)

10+ Year Member



[QUOTE=Kailash Badu;3517945]by receiving $_GET['id'] and matching it to an email address in your database you could assume that a particular email has been opened by a particular user. The next step depends on your application logic. Do whatever you originally intended to do (think, why do I want to know if the user opened the email)![/QUOTE]

ok...
I used the following code for email.php.
and when i wrote [url]http://www.example.com/track/email.php?userid=111[/url]
I got the image but no entry in the database? What could be the reason?

<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("sqldb", $con);

$userid = $_GET['userid'];

$sql="INSERT INTO quote (contributed_by)
VALUES
('$_GET[userid]')";

mysql_close($con);
?>
<img src="http://www.example.com/gallery/mj_1.jpg">

also is there any way i can increment the userid on it's own rather than sending userid=1 to 1st email and userid=2 to second email if i have around 100 emails; i just want an entry in the data base how all the id's that have viewed?

[edited by: dreamcatcher at 10:13 am (utc) on Aug. 21, 2007]
[edit reason] Use example.com, thanks. [/edit]

venelin13

9:11 am on Aug 21, 2007 (gmt 0)

10+ Year Member



RE: I got the image but no entry in the database? What could be the reason?

It seems you never execute the query! You are missing mysql_query() posrtion here:

$sql="INSERT INTO quote (contributed_by)
VALUES
('$_GET[userid]')";

mysql_query($sql) or die(mysql_error());

mysql_close($con);