Results 1 to 8 of 8

Thread: send email onload

  1. #1
    Join Date
    Apr 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default send email onload

    Is there a way to send out an email to a certain address, every time a particular page has loaded?

    I searched for the answer, and can't seem to find anything about it.

    Maybe it's not possible.

    If it is possible, can someone tell me if I can do it with javascript.

    Thanks,
    Kim

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You could use AJAX (a form of javascript) to call a PHP (or any other server-side script) that would then send the email. You wouldn't be able to do it with just javascript though. Then again, if you go that route, you may want to just use the server side language directly.

    //EDIT: If you would like the basics of sending email using PHP and a mail server, simply use the following:

    Code:
    <?php
    $to = "me@mydomain.com"; //the address the email is being sent to
    $subject = "This is the subject"; //the subject of the message
    $msg = "This is the message"; //the message of the email
    
    mail($to, $subject, $msg, 'From: PHP Script <noreply@domain.com>'); //send the email.
    ?>
    Either way, hope this helps.
    Last edited by thetestingsite; 04-12-2007 at 11:59 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I think the OP was looking for a client-side solution.
    There was a post a while back that John wrote a function for, using the mailto protocol.

    If the OP can use PHP and has an SMTP server, that will work fine.
    - Mike

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Well, if you were to use the mailto function then that would just open the default mail browser on the user's computer. They would then have to hit the send button in that program to send the email. If the OP wants a somewhat "automatic response" from site (that sends the email), then PHP or some other server-side language with and SMTP server would be the best bet.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Apr 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks for helping...

    Yes, I am looking for something automatic.

    When a person loads a particular page on my website, I want a script to automatically send me an email.

    so I understand how to use a php script to send the email. The problem I'm having now is how to call the php script using javascript.

    I know how to do this with a submit button, but I want it to run the php when a page loads. I don't want the person to have to click anything.

  6. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    If you are looking for sending a mail while the visitor visits a particular page only using client-side JavaScript (not Ajax) it may not be possible. As thetestingsite stated using Ajax you might be able to do so.

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Do it server-side. The end.
    Ajax requires javascript supported and enabled, and STILL requires the PHP script anyway.
    Really.... no point in trying to go around it.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Apr 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by kimberlyhello View Post
    so I understand how to use a php script to send the email. The problem I'm having now is how to call the php script using javascript.
    Don't put any javascript in the page, you don't need to. just put the php in anywhere in the page and change the file extension of the page from ".html" to ".php". Easy

Bookmarks

Posting Permissions

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