Current location: Hot Scripts Forums » Programming Languages » PHP » How to Include JavaScript feature in email messages


How to Include JavaScript feature in email messages

Reply
  #1 (permalink)  
Old 05-27-05, 07:23 AM
hifibee hifibee is offline
New Member
 
Join Date: May 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
How to Include JavaScript feature in email messages

hi, the query is i have to send an html page to a user mail. the html page contains some input fields and a submit button with the javascript validations. the problem is i want to validate the input fields when i click the submit button and submits the page to the specified location. these actions should be done when the user opens the e-mail page.

hope u got it
Reply With Quote
  #2 (permalink)  
Old 05-27-05, 10:07 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

<?php


//these are the fields
$name $_POST['name'];
$email $_POST['email'];
$subject $_POST['subject'];
$message $_POST['message'];
//etc

//validation
if ((!$name) || (!$email) || (!$subject) || (!$message)) {
die (
"Please fill out all of the fields!");
}

//send mail
else {
mail("youremail@site.com"$subject$message"From: $name<$email>");
echo 
"Thank you, your email has been sent!";
}

?>
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #3 (permalink)  
Old 05-27-05, 11:17 PM
hifibee hifibee is offline
New Member
 
Join Date: May 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
thnx for your suggestion. what i need is to send an html page as an email. when i open my inbox the page should be shown in my account. when i click the submit button the values should be posted to another page. any valuable suggestions are welcome.

thnx in advance
Reply With Quote
  #4 (permalink)  
Old 05-28-05, 08:07 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

It is not generally a good idea to send an HTML that is somewhat interactive, like your JS (JavaScript) validation, via email. The thing is that, while some mailers do support HTML messages, the way each mailer deals with such emails differs very much from one another.

For instance, my mailer is capable of receiving HTML messages (though I configured it so that I don't receive such messages, like many others do), yet it automatically strips all JS and other scripting codes before it even gets into my inbox. This is only one example, and I thought Hotmail does more or less the same thing, and so forth.

Furthermore, input validation with JS is not reliable at all, and depending on the kind of data you are dealing with, you should stay away from using it or shouldn't count on it too much anyway - instead, use PHP or other server-side scripting language that the users will have no control over.

Now, back to the topic. What I would recommend is simply give a link to an online form on your site, intead of sending it in the email. I understand this is not really what you wanted to hear, but this way, you can ensure the single point of input (and thus validation) and everyone, no matter what mailer he/she uses, can access your online form eventually.

Also, if you really want (or need) to send out HTML messages, consider using multipart messages for those who have mailers with HTML message disabled. Here's a good example:

http://www.zend.com/zend/trick/html-email.php

HTH.
__________________
Blavv =|
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with javascript and formatting email output sturmdogg JavaScript 1 04-26-05 03:39 AM
Include PHP via javascript bkbenson JavaScript 4 02-19-05 12:40 AM
how to make javascript works in email? seyyen JavaScript 1 12-01-04 10:20 AM


All times are GMT -5. The time now is 06:48 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.