1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

PHP PHP Mail Form

Discussion in 'Web Development' started by vareside, Oct 10, 2008.

  1. vareside

    vareside New Member

    Hi folks,

    during the last weeks I got a bit confused and busy due to school work. I would like to build a small e-mail-service where the user can send messages to an e-mail-adress of his/her choice.

    The form should basically contain 5 fields.
    1. Name
    2. E-Mail (from)
    3. E-Mail (to)
    4. Subject
    5. Message

    And if it's possible, to prevent spam, an image-code you have to enter "to verify that you are a human".

    Kind regards,
    vareside
     
  2. anishk177@gmail.com

    anishk177@gmail.com New Member

  3. bmcoll3278

    bmcoll3278 New Member

    Easy script but you would open to big problems from spam unless it it password protected.

    I will try to log in tomorrow and paste the code in for you but I would not use it unless you password protect the page
     
  4. dynamark

    dynamark New Member

    small time e-mail service to my registered viewers.

    Hi friends,

    I would also like to build a small e-mail-service where the user can send messages to an e-mail-address of their choice.

    The form should basically contain 5 fields.
    1. Name
    2. E-Mail (from)
    3. E-Mail (to)
    4. Subject
    5. Message
    6. My Ad at the bottom in a text form

    And if it's possible, to prevent spam, a special-code has to be entered "to verify that the sender is registered with us". If you get sufficient help do let me know the details of the same.

    Kind regards,
    dynamark
     
  5. bmcoll3278

    bmcoll3278 New Member

    Ok I can not do anything about making sure they are a member but you can place the script in a folder that can only be accessed buy a registered user.

    I uploaded this to my site and tested it. It does work be sure to set the permissions to 755 on the files after you get them on your server.

    code for the form
    Code:
    <div> <table width="60%"><tr><td>
    <form method="post" action="send.php"onsubmit="return validate_form(this)">
    
    Your Name: </td><td><input type="text"name="name"/></td><tr><tr><td>
    
    Your Email: </td><td><input type="text"name="email"/></td><tr><tr><td>
    
    Email your sending to: </td><td><input type="text"name="send"/></td><tr><tr><td>
    
    Subject: </td><td><input type="text"name="subject"/></td><tr><tr><td>
    
    
    Message:</td><td>
    <textarea name="message" rows="10" cols="30">
    
    
    </textarea></td></tr><tr><td>
    <input type="submit" value="send message"/>
    </form>
    	</td></tr></table>		
    		</div>
    save this code as send.php

    Code:
    <?php 
    $name=$_REQUEST['name'];
    $email=$_REQUEST['email'];
    $send=$_REQUEST['send'];
    $subject = $_REQUEST['subject'] ;
    $message = $_REQUEST['message'] ;
      
    
    $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
      
      mail ("$send", "$subject", "$message","$header") ;
    
      echo"<h1>Your message has been sent</h1>";
    
    
    ?>
    This is the javascript to paste into the header section of your page it will not let the form be submitted without senders email address entered.

    Code:
    <script type="text/javascript">
    function validate_required(field,alerttxt)
    {
    with (field)
      {
      if (value==null||value=="")
        {
        alert(alerttxt);return false;
        }
      else
        {
        return true;
        }
      }
    }
    
    function validate_form(thisform)
    {
    with (thisform)
      {
      if (validate_required(email,"Email must be filled out!")==false)
      {email.focus();return false;}
      }
    }
    </script>
    I will remove this in 24 hours but I left it for you to see how it looks

    http://www.bmcoll.com/testfolder/mailform.html

    Send your self an email with it .