Page 1 of 2

Problem with HTML email with Javascript

Posted: Tue Mar 15, 2005 12:42 pm
by windforceus
Hi All

I am using php script to send html email with javascript. It work fine in outlook but when i send to yahoo and hotmail. What i see from yahoo is my html email with javascript plain text. I think yahoo convert my javascript to plain text in the email.

Is there anyway to make an html email and javascript effect work in yahoo?

Please help!! this is urgent

Ray

Posted: Tue Mar 15, 2005 12:47 pm
by feyd
post some code?

Posted: Tue Mar 15, 2005 2:31 pm
by Ambush Commander
I don't see why you need JavaScript in your email messages: it's too risky security-wise, and Yahoo has good reason for doing it. Have you commented out the script parts?

Thanks for reply

Posted: Tue Mar 15, 2005 3:57 pm
by windforceus
I am researching to get response from client when he/she open the email for marketing purpose. I don't intend to hack people's computer. Here is the simplied code:

Code: Select all

<?php
//session_start();
require_once("db_cns.php");
require_once("htmlMimeMail5/htmlMimeMail5/htmlMimeMail5.php");

$text2 = "
<html>
<head>
<title>Untitled</title>
<script language=\"JavaScript\" type=\"text/javascript\">

window.onload = function () {

	
		var today = new Date();
		var expire = new Date();
		var cookieValue=\"1\";
		var name =\"view1\";
		var cookieFound = 0;
        var start = 0;
        var end = 0;
        var CookieString = document.cookie;

		var myvar;
        var i =0;
        while (i <= CookieString.length) {
                start = i;
                end = start + name.length;
                if (CookieString.substring(start,end) == name) {
                        cookieFound = true;
                        break;
                }
                i++;
        }

		if (cookieFound==false) {
				expire.setTime(today.getTime() + 3600000*24*1);
				
				document.directForm.submit();
		}
		
}
</script>

</head>
<body >

HTML
<FORM 
  NAME=\"directForm\" 
  ACTION=\"http://localhost/email/email/test.php\" 
  METHOD=\"get\"
  ENCTYPE=\"multipart/form-data\">
<input type=\"hidden\" name=\"cid\" value=\"1000\"> 
</form>
</body>
</html>


";


 // Instantiate a new HTML Mime Mail object
    $mail = new htmlMimeMail5();

    // Set the sender address
   // $mail->setFrom("rayh@ablecomp.com");
     $mail->setFrom("email");
    // Set the reply-to address
    $mail->setReturnPath("email");

    // Set the mail subject
    $mail->setSubject("Test HTML Mime Mail");

    // Set the mail body text
   $mail->setText("HELL0");

	 // Create the HTML email
    $mail->setHTML($text2);


    // Send the email!
   $mail->send(array("email"));

feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Mar 15, 2005 4:08 pm
by feyd
use an image to track when they opened the file. The cookie information, if they are viewing it on Yahoo, will tell you Yahoo's cookie information. Not your own.

Alternately, you can give people a plain-text version with a link to a nice prettified version, unique to them if need be.

I'd be surprised if outlook's works correctly.. not to mention your Javascript code may easily produce a false positive because 'view1' may appear almost anywhere inside the cookie data.

Thanks for reply

Posted: Tue Mar 15, 2005 4:13 pm
by windforceus
THe cookie name will be reconsidered , thanks. It is the test version. Besides cookie, anyway we can trace the response? I am looking for the automatic loading way because users may not want to click the link then it will result the incorrecness.

Posted: Tue Mar 15, 2005 4:15 pm
by feyd
as I said, an image works well too.. however, the user must allow images to be displayed.. which a lot of email clients are now making optional, if not already.

Image?

Posted: Tue Mar 15, 2005 4:17 pm
by windforceus
Can you be more specific? How to use image to trace it?

a popout window with image?

Posted: Tue Mar 15, 2005 4:19 pm
by windforceus
just a guess

Posted: Tue Mar 15, 2005 4:41 pm
by feyd
there is no Javascript involved. You simple place an image with trackable data that requests from your client's site. This could be a php script that stores access times and who the email was sent to that is requesting the image.. blah blah..

Posted: Tue Mar 15, 2005 5:06 pm
by Ambush Commander
As an email user, I despise attempts at tracking whether or not I have read email and whole-heartedly block any external images I may find in my email messages.

Do you really need this functionality? Can you do without it?

ahh..

Posted: Tue Mar 15, 2005 5:29 pm
by windforceus
I can do programming in php which will make this easiler. However, I can only do this in html file. That is what my boss is asking...He want to trace people reading his ad html. Thanks for the advice...hope someone can help me....

To feyd

Posted: Tue Mar 15, 2005 5:39 pm
by windforceus
"an image with trackable data that requests from your client's site. "?

Say we have an image in html file. How did you put an trackable data in client site? My understanding is storing images in the server and puting image links in the htm email. When the email is open, it will load image from our server. Then we can use php script to store the times? Perhaps i am wrong or...sorry i am a newbie.

Ray

Posted: Tue Mar 15, 2005 5:41 pm
by Ambush Commander
Oh... then the image idea is what you should do. Here's a sample.

Inside the HTML email mesage, you have this:

Code: Select all

&lt;img src=&quote;http://www.yourdomain.com/dump/track.php?userid=234810&quote; /&gt;
then,

Code: Select all

&lt;?php

$id = is_numeric($_GET&#1111;'userid']) $_GET&#1111;'userid'] ? null;
session_start();
header('Content-type: image/jpeg');
$image = imagecreatefromjpeg(&quote;Path to jpeg you want to show up as a picture&quote;);
imagejpeg($image);

//And then logging: (ripped this code off http://www.phpfreaks.com/tutorials/22/0.php )


if(!session_is_registered('counted')){
    $agent = $_SERVER&#1111;'HTTP_USER_AGENT'];
    $uri = $_SERVER&#1111;'REQUEST_URI'];
    $user = $_SERVER&#1111;'PHP_AUTH_USER'];
    $ip = $_SERVER&#1111;'REMOTE_ADDR'];
    $ref = $_SERVER&#1111;'HTTP_REFERER'];
    $dtime = date('r');
    
    if($ref == &quote;&quote;){
        $ref = &quote;None&quote;;
    }
    if($user == &quote;&quote;){
        $user = &quote;None&quote;;
    }
    
    $entry_line = &quote;$dtime - IP: $ip | Agent: $agent  | URL: $uri | Referrer: $ref | Username: $user | Userid: $id \n&quote;;
    $fp = fopen(&quote;logs.txt&quote;, &quote;a&quote;);
    fputs($fp, $entry_line);
    fclose($fp);
    session_register('counted');
} 
?&gt;

Ambush

Posted: Tue Mar 15, 2005 5:47 pm
by windforceus
You are using session in an html file? Is it possible for yahoo.mail showing the compiled php code in html email? Thanks for the idea.

Ray