www.webdeveloper.com
Results 1 to 12 of 12

Thread: Sending a message from html page

  1. #1
    Join Date
    Apr 2012
    Posts
    5

    Sending a message from html page

    Hi there,

    I'm new to HTML and JavaScript, and am trying to build a personal website, or more specifically, one with a contact page. If I wanted to have a "comment" type box, whereby I type the text into a box, push a button, and have the text sent to my email address? I have seen things similar to this in other websites, but I'm not sure if they have the text sent to an email like I want to do. Would anyone be able to help?

  2. #2
    Join Date
    Mar 2012
    Posts
    202
    Quote Originally Posted by AdenAlcorn View Post
    Hi there,

    I'm new to HTML and JavaScript, and am trying to build a personal website, or more specifically, one with a contact page.
    If you are new to something, you should be spending more of your time trying to learn it than do it. Programming is not something that you can jump into and think everything is just going to work.

    Anyways, browsers can handle sending email through the mailto: protocol http://en.wikipedia.org/wiki/Mailto

    If you are looking to handle it as a form, then you need to have something like a PHP server with the correct PHP code on it to handle the form input and possibly do the SMTP (mail) transaction.

    And please, if you expect to receive any help, at least make an attempt to try. Post some code.

  3. #3
    Join Date
    Nov 2010
    Location
    Los Angeles, CA
    Posts
    234
    I built exactly this on my personal web site: http://www.sarksap.com/pages/contact.php

    It's an AJAX form that sends the email without refreshing the page. If you want to do it this way, read up how to make and handle an AJAX request (I used jQuery: http://api.jquery.com/jQuery.ajax/) to send the form data to a php script on the server. Then with php I used the mail() function to send the message: http://php.net/manual/en/function.mail.php

  4. #4
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    just make a new google form and paste the embed code into your website.

  5. #5
    Join Date
    Apr 2012
    Posts
    5
    Thanks Big O, I'm reading up on the link you gave me now. It seems a lot more complicated than I had expected.

    Great site, by the way

  6. #6
    Join Date
    Apr 2012
    Posts
    5
    Big O, How do I tie the jQuery and PHP scripts together? The jQuery has examples of it's text, and likewise with the PHP, but there are no examples of how they are tied together?

  7. #7
    Join Date
    Mar 2012
    Posts
    202
    Quote Originally Posted by AdenAlcorn View Post
    Big O, How do I tie the jQuery and PHP scripts together? The jQuery has examples of it's text, and likewise with the PHP, but there are no examples of how they are tied together?
    - jQuery is JavaScript (Client-Side)
    - PHP is .. PHP (Server-Side)

    There are two computers here. The "Server", and the "Client". The "Server" reads the PHP, and from that it gets the necessary JavaScript/HTML and sends that to the client. The "Client" reads HTML/JavaScript and from that you get what you are looking at right now...

    One does not simply "tie" PHP with jQuery

  8. #8
    Join Date
    Apr 2012
    Posts
    5
    Hi Gray,

    Thanks for replying, it helped a lot. However, what I was trying to ask is this;

    If one is to create a comment/message box, they would have to do it with HTML/JavaScript. However, to have the message box become functional, and send it's content to a specific location, i.e., an email address, the need PHP (from what I'm aware of)

    Earlier on the posts, Big O sent: "I used jQuery...to send the form data to a php script on the server"

    I'm not sure if I'm succeeding in asking my question how I'm thinking it. When a person wants to add CSS to a script they type "<script type="text/css">" if they want to add JavaScript, they say, "<script type="text/javascript">"...so they can "tie" the two scripts onto the one page. How would one do this with PHP? Type, "<script type="text/php">"?

  9. #9
    Join Date
    Mar 2012
    Posts
    202
    Quote Originally Posted by AdenAlcorn View Post
    Hi Gray,

    Thanks for replying, it helped a lot. However, what I was trying to ask is this;

    If one is to create a comment/message box, they would have to do it with HTML/JavaScript. However, to have the message box become functional, and send it's content to a specific location, i.e., an email address, the need PHP (from what I'm aware of)

    Earlier on the posts, Big O sent: "I used jQuery...to send the form data to a php script on the server"

    I'm not sure if I'm succeeding in asking my question how I'm thinking it. When a person wants to add CSS to a script they type "<script type="text/css">" if they want to add JavaScript, they say, "<script type="text/javascript">"...so they can "tie" the two scripts onto the one page. How would one do this with PHP? Type, "<script type="text/php">"?
    The following is invalid. CSS is not a type of "script"

    Code:
    <script type="text/css">
    And as I said earlier, PHP is done on the server-side. PHP is a language used to generate the HTML/CSS/JavaScript that the browser uses.

    This is a PHP example to generate a simple string used in HTML:

    PHP Code:
    <?php
    echo "HTML OUTPUT"
    ?>
    You *NEED* to put the file on a PHP server, even just to test the PHP. I think instead of asking questions here you should probably be looking at basic PHP tutorials. Make sure you read the information about PHP form handling, but try not to skip anything...
    Last edited by Gray1989; 04-13-2012 at 12:26 PM.

  10. #10
    Join Date
    Apr 2012
    Posts
    55
    To answer your question, PHP is "tied" into HTML with <?php ... ?>:

    PHP Code:
    <!doctype html>
    <html>
        <head>
            <title>simple php example</title>
        </head>
        <body>
            <?php
                
    // Here's where you put your PHP script
                
    for($i 1$i <= 10$i++) {
                    echo(
    $i ' ');
                }
            
    ?>
        </body>
    </html>
    However, as Gray is saying, if save this as a .html file and try to open it in a web browser it won't execute the PHP part because the browser doesn't have a PHP interpreter. This is something you would upload to a PHP server (as a .php file) and then retrieve from the server. The server preprocesses the PHP scripts and returns an HTML file.

    If you don't have a PHP server then I would take this suggestion to handle your current situation:

    Quote Originally Posted by rnd me View Post
    just make a new google form and paste the embed code into your website.
    And by all means learn about PHP! If you want to learn, you can get a PHP server on your computer. If you're a Windows user, look up XAMPP for information on installing a PHP server on your own computer. Or if you have Windows Professional or Home Premium you can use IIS. But actually getting a PHP script to do what you want is a ways off if you've never set up a server before.
    Last edited by nathanwall; 04-13-2012 at 01:30 PM.
    joi JavaScript Framework - the sunnier side of JavaScript.

  11. #11
    Join Date
    Mar 2012
    Posts
    202
    Quote Originally Posted by nathanwall View Post
    And by all means learn about PHP! If you want to learn, you can get a PHP server on your computer. If you're a Windows user, look up XAMPP for information on installing a PHP server on your own computer. Or if you have Windows Professional or Home Premium you can use IIS. But actually getting a PHP script to do what you want is a ways off if you've never set up a server before.
    I use WampServer.. Have you tried it?

  12. #12
    Join Date
    Apr 2012
    Posts
    5
    Thanks for the help Nathanwall

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