Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Simple HTML question?

I need to know what the tag is to have a form send to an email automatically without opening the visitors email client.

Like a 4 field form where it sends the data from the text fields to my email with the click of the "send" button.

Update:

Awesome!

Thanks guys!

3 Answers

Relevance
  • Aaron
    Lv 4
    1 decade ago
    Favorite Answer

    This functionality is provided by the web server.

    The web form itself cannot perform the mailing.

    You need a script that takes the values found in your form and then calls the mail program on the server to actually deliver it.

    Here's a walkthrough:

    The first thing we need to do is to write the feedback form itself. Put the following code in the <body> section of an HTML file named, say, feedback.html.

    <form method="post" action="sendmail.php">

    Email: <input name="email" type="text" /><br />

    Message:<br />

    <textarea name="message" rows="15" cols="40">

    </textarea><br />

    <input type="submit" />

    </form>

    Basically the form asks the visitor for his email address (the field named "email" found in input name="email" above) and message (the field named "message" found in textarea name="message"), and presents him with a button which he can click to submit the contents of the form. When the form is submitted, it is "posted" (see the "method" attribute of the <form> tag) to a script named "sendmail.php" (also specified in the <form> tag).

    The Feedback Form PHP Script

    Now all that remains is to code "sendmail.php". This is made extremely easy by the facilities available in PHP. Type the following code into a file named "sendmail.php". Do not put anything else into that file, ie, don't put in any other HTML tags or headers, etc.

    <?php

    $email = $_REQUEST['email'] ;

    $message = $_REQUEST['message'] ;

    mail( "yourname@example.com", "Feedback Form Results",

    $message, "From: $email" );

    header( "Location: http://www.example.com/thankyou.html%22 );

    ?>

    When the form is submitted to sendmail.php, the contents of the "email" field in the form is put into a PHP variable called $_REQUEST['email']. Likewise the contents of the "message" field is put into the variable $_REQUEST['message'].

    If you had named the fields in your form "emailofsender" and "contentsofmessage", then the information submitted in those fields would have been available to your script in the variables $_REQUEST['emailofsender'] and $_REQUEST['contentsofmessage'] respectively. I think you get the idea.

    The first thing we do in our PHP script is to make the information that is submitted easily accessible to the rest of the program.

    Firstly, we made a copy of the contents of $_REQUEST['email'] in a variable we call $email. This was done in the line

    $email = $_REQUEST['email'] ;

    Note that we don't really have to call this new variable $email - we could have called it $thingamajig if we wished, but it makes sense to name a variable with some meaningful name.

    Likewise, in the next line, we made a copy (assigned) of $_REQUEST['message'] in a variable $message.

    $message = $_REQUEST['message'] ;

    Again, we could have named the new variable anything we wanted - but it's easier for us to understand the program if the variable name reflects what it does.

    The real workhorse of this script is in the line beginning with "mail".

    mail( "yourname@example.com", "Feedback Form Results",

    $message, "From: $email" );

    mail is a special function in PHP that sends mail. The first parameter to mail is supposed to contain the email address you want the form contents to be sent to, such as your own email address. The second parameter is the "Subject" of the email message. The last two parameters are the content of the message and the headers you want sent, respectively. We want a "From" header so that we know who is sending the email to us and can reply to him/her if we need to.

    Notice that, like many other programming languages, strings (sequences of characters) are enclosed in double quotes, such as "Feedback Form Results".

    Variables like $message can be used as-is. Note also that you can also interpolate (introduce) the contents of the variable $email into a string, like "From: $email", so that if your $email string contained an address like "william@shakespeare.com", the final string that is passed to the mail function will be "From: william@shakespeare.com".

    You can also use single quotes (such as those in 'Hi there') to quote strings, but when you do so, the variables included are not expanded. This is useful if, for some reason, you really want to pass the string 'From: $email' to mail without PHP translating that to "From: william@shakespeare.com".

    You can't interpolate variables like $_REQUEST['email'] and $_REQUEST['message'] in the same way, which is why we assigned their contents to $email and $message. The latter are also easier to read anyway.

    Finally, it is appropriate to thank the visitor for his message. This is done with the line

    header( "Location: http://www.example.com/thankyou.html%22 );

    This line causes PHP to send an HTTP header back to the visitor's browser telling it to load the URL "http://www.example.com/thankyou.html%22. The "header" function allows us to send any HTTP header to the browser.

    You will of course have to create such a file called "thankyou.html"

  • 1 decade ago

    This is just a something that can maybe spark some thinking so that you can get the form just right for you site.

    <form method="post" action="mailto:youremail@email.com">

    <textarea rows="5" cols="20" wrap="physical" name="comments">

    Enter Comments Here

    </textarea>

    <input type="submit" value="Email Yourself">

    </form>

  • 5 years ago

    i understand the style you sense... Dreamweaver and Frontpage the two upload their very own jargon in there that wreaks havoc as quickly as I code; enormously whilst the pages are examined pass browser / platform... To be easy, i take advantage of stable old Notepad... and if I even have slightly of extra coding that i desire executed much less complicated, i take advantage of Dreamweaver, and then sparkling all of it up in Notepad afterwards. desire this helps! stable success jointly with your projects! :)

Still have questions? Get your answers by asking now.