Problem with HTML email with Javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

windforceus
Forum Newbie
Posts: 23
Joined: Tue Mar 15, 2005 12:40 pm

Problem with HTML email with Javascript

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post some code?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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?
windforceus
Forum Newbie
Posts: 23
Joined: Tue Mar 15, 2005 12:40 pm

Thanks for reply

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
windforceus
Forum Newbie
Posts: 23
Joined: Tue Mar 15, 2005 12:40 pm

Thanks for reply

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
windforceus
Forum Newbie
Posts: 23
Joined: Tue Mar 15, 2005 12:40 pm

Image?

Post by windforceus »

Can you be more specific? How to use image to trace it?
windforceus
Forum Newbie
Posts: 23
Joined: Tue Mar 15, 2005 12:40 pm

a popout window with image?

Post by windforceus »

just a guess
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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?
windforceus
Forum Newbie
Posts: 23
Joined: Tue Mar 15, 2005 12:40 pm

ahh..

Post 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....
windforceus
Forum Newbie
Posts: 23
Joined: Tue Mar 15, 2005 12:40 pm

To feyd

Post 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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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;
Last edited by Ambush Commander on Tue Mar 15, 2005 6:07 pm, edited 1 time in total.
windforceus
Forum Newbie
Posts: 23
Joined: Tue Mar 15, 2005 12:40 pm

Ambush

Post 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
Post Reply