www.webdeveloper.com
Results 1 to 12 of 12

Thread: Receive value from URL, then automatically email it.

  1. #1
    Join Date
    Mar 2005
    Posts
    23

    Question Receive value from URL, then automatically email it.

    Ok, what I want is probably a pretty simple task, I just don't know how to do it. I want be able receive a value from a URL such as:

    www.domain.com?ID="12345"

    First, I am assuming the 12345 needs to be in quotes.

    I also want to capture the user's IP address. Next, I want to automatically email both values to my email address.

    What would be the best way to do this?

    Please include details for us people who are not real good at this. I would really appreciate your help.

    Thanks.

  2. #2
    Join Date
    Jul 2003
    Location
    Boston Area, Massachusetts
    Posts
    3,489
    Since you posted in the HTML section, I'm assuming you think this can be done on the client-side alone (i.e., HTML/JavaScript/etc.). This is not the case. You'd need server-side. PHP, among other languages, can do this with ease.

    And just so you know, the value of the query string (everything after the "?" in a URI) does not need to be quoted. What you're after is going to be done something like this:
    Code:
    <?php
       mail( 'you@whatever.com', 'test', 'Querystring: ' . $_GET['id'] . '\nIP: ' . $_SERVER['REMOTE_ADDR'] );
    ?>
    First you'd have to verify that your server allows PHP scripting...

  3. #3
    Join Date
    Mar 2005
    Posts
    23
    Yeah, I new I would need more, but I thought I would start here. Could it be done here without getting the users IP? I didn't think you could automatically launch something in just HTML, but I thought I would try. I will move this over to the PHP area and ask more questions. I don't completely understand what I need to do with the code you gave me. I am completely PHP illiterate.

    Thanks.

  4. #4
    Join Date
    Mar 2005
    Posts
    23

    Unhappy

    Hmmm. There is no PHP area here.

  5. #5
    Join Date
    Jul 2003
    Location
    Boston Area, Massachusetts
    Posts
    3,489
    No. There is no way to send e-mail in the background, client-side. You can, in theory, use the "mailto:" protocol... but that is very messy and doesn't work in every instance (e.g., if the user's client isn't set up properly or they don't have a client to begin with).

    Now, as for PHP. Make a file called info.php. Have this inside of it:
    Code:
    <?php phpinfo(); ?>
    Upload this to your server, and then visit yourdomain.com/info.php. If you see page with a ton of PHP information, you have PHP installed and functioning properly on your server.

    If you get this far, all you need to do is then make a file called test.php, and then include the code I previously gave you within it. To "use" the script, just link to the file like this:
    Code:
    <a href="test.php?id=string">test</a>
    You can also type in the ID manually in the location bar, but I'm not sure how you want to approach this.

  6. #6
    Join Date
    Mar 2005
    Posts
    23
    Thanks alot for your help. I know that php is installed on my server and it works. I have a couple of other scripts running.

    Would it be very difficult to modify the code that you gave me to have it not send email if the ID value was not in the URL?

    Thanks.

  7. #7
    Join Date
    Jul 2003
    Location
    Boston Area, Massachusetts
    Posts
    3,489
    Oh, nice. Yeah, it's extremely easy. Just before the call to mail:
    Code:
    if( !empty($_GET['id']) )
    P.S. No problem...

  8. #8
    Join Date
    Mar 2005
    Posts
    23
    Hey, that works great. Now, I have a couple more questions. How do I either place this in an html file or redirect to an html file after it has performed it's mail send? I tried placing this same code in an html file and calling:

    file.html?id=string

    But, it doesn't work. I tried it in the body, and then I tried it before the <html> tag at the beginning of the file. Neither one worked.

    Please let me know soon.

    Thanks.

  9. #9
    Join Date
    Jul 2004
    Location
    Sendai, Japan
    Posts
    1,273
    Put (something like) this at the end of the code - it'll perform the necessary action, then redirect to a web page :

    Code:
    header("Location: http://www.mywebsite.com/mypage.htm");
    (You need the full url).

  10. #10
    Join Date
    Mar 2005
    Posts
    23
    Quote Originally Posted by BonRouge
    Put (something like) this at the end of the code - it'll perform the necessary action, then redirect to a web page :

    Code:
    header("Location: http://www.mywebsite.com/mypage.htm");
    (You need the full url).
    Cool. I'll try that.

    Does anyone know why the script worked as a php file, but did not work when imbedded in an html file?

  11. #11
    Join Date
    Jul 2004
    Location
    Sendai, Japan
    Posts
    1,273
    PHP will only work if your file has a php extension. Your page can look like a regular html page (with the php stuck in the middle of it) - it just has to have a php extension. Also, I think (though I'm not 100% sure) if you use a redirect like that (header) you might need to put that before the html head.

  12. #12
    Join Date
    Mar 2005
    Posts
    23

    Smile

    All is good and understood now.

    Thanks for all you help guys. Everything is working 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