• home
  • forum
  • my
  • kt
  • download
  • Form to Email

    Author: 2007-08-13 09:48:49 From:

    You can apply this tutorial for your contact form on your sites. This tutorial shows you in 1 file with a normal contact information form. When you submit, this file will be sent an email immediately to the target email including in codes.


    form_to_email.php

    Source Code
    <?
    // Check, if submitted.
    if($Submit){

    /*
    Send email to "webmaster@localhost".
    If you want to send more than 1, use "," between the second, third,...
    Ex. webmaster@localhost, me@domain.com, you@domain.com, ...
    */

    $to="webmaster@localhost";

    $subject="Contact information from website.";

    // Get time from server.
    $time=date("d/m/Y");

    $mail_from="From:$email \n";
    $mail_from .="Content-Type: text/html; charset=utf-8 \n";
    $message="
    Contact on : $time<br>
    Name : $name<br>
    Email : $email<br>
    Comment : $comment
    ";

    // Send email.
    mail($to,$subject,$message,$mail_from);
    echo "Your contact information has been sent";
    }else{

    // Do following codes if not found "Submit" value.(Not submitted)
    ?>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    <form action="<? echo $PHP_SELF; ?>" method="post" name="form" id="form">
    <table>
    <tr>
    <td align="right">Your name : </td>
    <td><input name="name" type="text" id="name" /></td>
    </tr>
    <tr>
    <td align="right">Your Email : </td>
    <td><input name="email" type="text" id="email" /></td>
    </tr>
    <tr>
    <td align="right" valign="top">Comment/ Request : </td>
    <td><textarea name="comment" cols="60" rows="5" id="comment"></textarea></td>
    </tr>
    </table>
    <input type="submit" name="Submit" value="Submit Form" />
    </form>
    </body>
    </html>
    <? } ?>

     
    • Copy this code and save as form_to_email.php to your root folder, open this file by browse to http://localhost/form_to_email.php.
    • Fill in all text fields and click "Submit" button.
    • Open your email client program to recieve email.

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (6)
      Discussion Boards (7)
      E Commerce (6)
      Email Systems (9)
      Error Handling (5)
      File Manipulation (10)
      Flash and PHP (4)
      Form Processing (7)
      Guestbooks (8)
      Image Manipulation (3)
      Installing PHP (5)
      Introduction to PHP (9)
      Link Indexing (6)
      Mailing List Management (8)
      Miscellaneous (10)
      Networking (6)
      News Publishing (6)
      OOP (8)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (5)
      Postcards (0)
      Randomizing (8)
      Redirection (8)
      Searching (6)
      Security (6)
      Site Navigation (7)
      User Authentication (10)
      WAP and WML (7)
      Web Fetching (0)
      Web Traffic Analysis (11)
      XML and PHP (0)

    New

    Hot