I am new in javascripting and I am looking for a javascript that will be used to send the content of a message window with email to me. The reason for that is that I created a search engine and the result's page is a pop-up message box. On this message box I want to include a button to send the results to myself with an email.
$25, ouch!
Cardiff13, I recommend you find out what you have for server side scripting. If you have PHP, Perl, Python, or even Ruby I can help you write something up real quick.
My Site
Web Design On Linux: Sure It Takes Longer To Get It Right In IE, But Who Really Cares?
Cool. Well, first, how is the data getting sent to the content window?
If it is coming off of a form or something we can do this is one fell swoop.
PHP Code:
$message = "Type some of your email here then when you need a variable from the form you can stick it in like so: " . $_POST['nameOfTheFormField'] . " See?";
if(mail("toAddress@example.com", "Subject Line", $message))
{
print "Sweet, it sent the email!";
}
else
{
print "Dangit! It didn't send the mail.";
}
If you want to do it in two steps (display, confirm-send) or you use the form data to fetch content from somewhere else, this'l take some tweaking.
My Site
Web Design On Linux: Sure It Takes Longer To Get It Right In IE, But Who Really Cares?
Hmmm...er, my javascript is lacking. I believe you could do this two ways.
First way is to also write all of that stuff (sans the submit button) into a hidden field in a form for that submit button. You'd have to escape stuff like crazy.
Other option is to scrape the whole page into that hidden var at the end. Something like,
Code:
var contents = MsgBox.document.body.innerHTML;
Then shove it all into a hidden form field again. Honestly can not think of a better way.
My Site
Web Design On Linux: Sure It Takes Longer To Get It Right In IE, But Who Really Cares?
Can you please tell me how I will create the hidden field in a form for the submit button? I am trying to find a way to put it into the existing code but then the script doesn't work. Probably I am doing something wrong.
Can you also tell me where I am putting the php code you wrote above?
Sorry for being pain in the ass, but as I said I am new in scripting.
Don't worry, everybody starts somewhere.
The way I'd do it is to go ahead and put it in the code, then reference it like this. I also change the form to have an action set to "mailit.php" and added a "Mail It!" button.
Code:
stats='toolbar=no,location=no,directories=no,status=no,menubar=no,height=350,width=300,'
stats += 'scrollbars=yes,resizable=yes'
MsgBox = window.open ("","msgWindow",stats)
MsgBox.opener = window;
MsgBox.opener.name = "opener";
MsgBox.document.write("<head><title>Search Results</title></head>");
MsgBox.document.write ("<body bgcolor=white text=black link=blue vlink=darkblue alink=blue><H2><CENTER><font face=arial>Search Results</CENTER></H2>")
MsgBox.document.write ("<font size=3><b><center>For the keyword:</b> "+Item+"</center><hr width=50%></font>");
for (var i=1; i <= Keyword[0]; i++) {
if(Item == Keyword[i]) {
if ( "T_T" == Property[i]) {
Found = true;
MsgBox.document.write ("<li><font face=arial><font size=2><b>"+Descrip[i]+"</b><BR><BR>The class "+Descrip[i]+" contains the property "+Property[i]+" and is connected to the class(es) "+Connection[i]+".<BR><BR><BR><BR><BR><BR></font></font>")
MsgBox.document.write ("<FORM><CENTER>")
MsgBox.document.write ("<font size=2><font color=arial><INPUT type='submit' value='Send Information' onClick = 'sendMail()'></font></font>")
MsgBox.document.write ("</CENTER></FORM>")
}
}
}
if(!Found)
MsgBox.document.write ("<H4>Nothing Found</H4><BR><font face=arial><font size=2>Either the class you are looking for does not exist or it does not contain the property T_T. Please search again.</font></font><BR><BR><BR><BR><BR><BR>")
MsgBox.document.write ("<FORM action='mailit.php' method='POST'><input type='hidden' id='hiddenstuff' name='hiddenstuff' value='' /><CENTER>")
MsgBox.document.write ("<font size=2><font color=arial><input type='submit' value='Mail It' /><INPUT type='button' value='Close Window' onClick = 'self.close()'></font></font>")
MsgBox.document.write ("</CENTER></FORM>")
MsgBox.document.getElementById('hiddenstuff').value = MsgBox.document.body.innerHTML;
}
So, with that you need to put that php on a page called mailit.php, like this.
PHP Code:
$message = $_POST['hiddenstuff'];
if(mail("toAddress@example.com", "Subject Line", $message))
{
print "Sweet, it sent the email!";
}
else
{
print "Dangit! It didn't send the mail.";
}
As that page stands, it should send the HTML content of the page to "toAddress@example.com"
I don't know how well it will actually do that though, because all the quotes in the page and tags might make it go crazy, but try that out and see how it goes.
My Site
Web Design On Linux: Sure It Takes Longer To Get It Right In IE, But Who Really Cares?
Bookmarks