www.webdeveloper.com
Results 1 to 12 of 12

Thread: SendMail Script

  1. #1
    Join Date
    Aug 2006
    Posts
    5

    SendMail Script

    Hi,

    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.

    Any suggestions?

    Cheers

  2. #2
    Join Date
    Jul 2006
    Location
    Nebraska
    Posts
    380
    Javascript can't send mail, you need something server-side.
    Try PHP and the PHPMailer class.

  3. #3
    Join Date
    Apr 2006
    Posts
    493
    had to pay 25$ for my CGI form mailer script. as PineSolPirate pointed out there is nothing client side, that will send an email automatically.

  4. #4
    Join Date
    Jul 2006
    Location
    Nebraska
    Posts
    380
    $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.

  5. #5
    Join Date
    Feb 2006
    Location
    Where I live, people get shot. I need to move.
    Posts
    634
    is that per month, quarter, year, 4eva?

    You could get a full years hosting plan with all bells and whisltes on it for around $50...

  6. #6
    Join Date
    Aug 2006
    Posts
    5
    Hey, thanks a lot for the quick responses guys.

    PineSolPirate: The server supports both PHP and CGI scripting. If you could help me I will be more than grateful.

  7. #7
    Join Date
    Jul 2006
    Location
    Nebraska
    Posts
    380
    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.

  8. #8
    Join Date
    Aug 2006
    Posts
    5
    Thenks for the quick response PineSolPirate.

    The data are taken from a form and are displayed on a message box.

    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><CENTER>") 
    MsgBox.document.write ("<font size=2><font color=arial><INPUT type='button' value='Close Window' onClick = 'self.close()'></font></font>") 
    MsgBox.document.write ("</CENTER></FORM>")
         }
    So, I want these data to be send to me with an email by clicking the button Send Information.

  9. #9
    Join Date
    Jul 2006
    Location
    Nebraska
    Posts
    380
    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.

  10. #10
    Join Date
    Aug 2006
    Posts
    5
    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.

  11. #11
    Join Date
    Jul 2006
    Location
    Nebraska
    Posts
    380
    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.

  12. #12
    Join Date
    Aug 2006
    Posts
    5
    Sweet!

    Thanks a lot for your help PineSolPirate. It works fine!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles