I need help creating a "Contact" form

Discussion in 'HTML & Website Design' started by UNBREAKABLE, Apr 14, 2010.

  1. #1
    UNBREAKABLE, Apr 14, 2010 IP
  2. frobak

    frobak Greenhorn

    Messages:
    81
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #2
    how much ya gonna pay me?
     
    frobak, Apr 15, 2010 IP
  3. nivedita011

    nivedita011 Peon

    Messages:
    97
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey, you don't need to pay anybody for such a simple form.

    You need to use the following code in the html page.
    <form method="POST" name="contactform" action="mail.php"> 
    
    			
    			<table width="100%" border="0" cellspacing="0" cellpadding="0">
    			
    
      <tr>
        <td align="right">Name: </td>
        <td align="right">
             <input type="text" id="TxtName" name="name" onkeypress="clearText();" size="33" /></td>
        <td rowspan="11" align="center" valign="middle">
         <input id="btnSubmit" type="image" src="images/submitbtn.png" value="Submit" name="submit" />
        
    </td>
      </tr>
      <tr>
        <td colspan="2" class="minirowspacer"></td>
        </tr>
      <tr>
        <td align="right">Email id :</td>
        <td align="right"><input type="text" id="TxtEmail" name="email" size="33" /></td>
        </tr>
      <tr>
         <td colspan="2" class="minirowspacer"></td>
        </tr>
      <tr>
        <td align="right">Contact No:</td>
        <td align="right">  <input type="text" id="TxtPhone" name="Phone" size="33" /> </td>
        </tr>
      <tr>
         <td colspan="2" class="minirowspacer"></td>
        </tr>
      <tr>
        <td align="right">Address:</td>
        <td align="right"><input type="text" id="TxtAddress" name="Address" size="33" />
    </td>
      </tr>
      <tr>
        <td colspan="2" class="minirowspacer"></td>
        </tr>
      <tr>
        <td align="right">Write your Query:</td>
        <td align="right"> <textarea id="txtMessage" name="message" cols="25" ></textarea></td>
      </tr>
      
    
      
      
    </table>
    </form>
    
    Code (markup):

    You need to create a php file named mail.php and put the following code in it
    <?php
    //new function
    $to = "info@yourdomain.com";
    $nameto = "SalesManager";
    $from = $_POST["Email"];
    $namefrom = $_POST["Name"];
    $subject = "Message/Query";
    $phone =  $_POST["Phone"];
    
    $address=  $_POST["Address"];
    if($address == NULL)
    $address=  " ";
    
    $comment=  $_POST["Message"];
    if($comment == NULL)
    $comment=  " ";
    
    //Construct Message
    $message = "Name: $namefrom" ;
    $message .= "<br />" . "Email: $from" . PHP_EOL;
    $message .= "<br />" . "Phone: $phone" . PHP_EOL;
    $message .= "<br />" . "Address: $address" . PHP_EOL;
    $message .= "<br />" . "<br />" ."Question/Comment: $comment" . PHP_EOL;
    
    
    try
    {
    echo 'Mail sending is in progress...' ;
    authSendEmail($from, $namefrom, $to, $nameto, $subject, $message) ;
    echo "Mail Sent Successfully";
    echo '<script type="text/javascript">window.location.href = "http://yourdomain.com/index.html?msg=yes" </script>';
    }
    catch(Exception $e)
     {
     echo $e->getMessage();
     echo "Mail Send failure";
     echo '<script type="text/javascript">window.location.href = "http://yourdomain.com/index.html?msg=no" </script>';
     }
    
    
    ?>
    
    <?php
    /* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */
    
    //This will send an email using auth smtp and output a log array
    //logArray - connection,
    
    function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
    {
    //SMTP + SERVER DETAILS
    /* * * * CONFIGURATION START * * * */
    $smtpServer = "mail.yourdomain.com";
    $port = "25";
    $timeout = "30";
    $username = "info@yourdomain.com";
    $password = "your password";
    $localhost = "localhost";
    $newLine = "\r\n";
    /* * * * CONFIGURATION END * * * * */
    
    //Connect to the host on the specified port
    $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
    $smtpResponse = fgets($smtpConnect, 515); // fgets( filenam, length )
    if(empty($smtpConnect))
    {
    $output = "Failed to connect: $smtpResponse";
    throw $output;
    }
    else
    {
    $logArray['connection'] = "Connected: $smtpResponse";
    }
    
    //Request Auth Login
    fputs($smtpConnect,"AUTH LOGIN" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['authrequest'] = "$smtpResponse";
    
    //Send username
    fputs($smtpConnect, base64_encode($username) . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['authusername'] = "$smtpResponse";
    
    //Send password
    fputs($smtpConnect, base64_encode($password) . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['authpassword'] = "$smtpResponse";
    
    //Say Hello to SMTP
    fputs($smtpConnect, "HELO $localhost" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['heloresponse'] = "$smtpResponse";
    
    //Email From
    fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['mailfromresponse'] = "$smtpResponse";
    
    //Email To
    fputs($smtpConnect, "RCPT TO: $to" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['mailtoresponse'] = "$smtpResponse";
    
    //The Email
    fputs($smtpConnect, "DATA" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['data1response'] = "$smtpResponse";
    
    //Construct Headers
    $headers = "MIME-Version: 1.0" . $newLine;
    $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
    $headers .= "To: $nameto <$to>" . $newLine;
    $headers .= "From: $namefrom <$from>" . $newLine;
    
    fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['data2response'] = "$smtpResponse";
    
    // Say Bye to SMTP
    fputs($smtpConnect,"QUIT" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['quitresponse'] = "$smtpResponse";
    
    
    }
    ?>	
    
    Code (markup):
     
    nivedita011, Apr 15, 2010 IP
  4. nivedita011

    nivedita011 Peon

    Messages:
    97
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    forgot to tell you that you need to change the url and email address to your email address wherever required
     
    nivedita011, Apr 15, 2010 IP
  5. carterstory

    carterstory Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you do a search for free PHP contact form, you will find tons..
    I wish I knew the name of the One I am using but can't seem to find it on any of the documentation I have found
     
    carterstory, Apr 15, 2010 IP
  6. UNBREAKABLE

    UNBREAKABLE Peon

    Messages:
    504
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks to everyone who DIDNT try to RIP ME OFF.
     
    UNBREAKABLE, Apr 15, 2010 IP
  7. syntaxerrorlagi

    syntaxerrorlagi Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    if you are using WP, just install a plugin called "Contact Form" it's free and very easy to use.
     
    syntaxerrorlagi, Apr 15, 2010 IP
  8. brightyoursite

    brightyoursite Peon

    Messages:
    59
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    brightyoursite, Apr 17, 2010 IP
  9. Piggy

    Piggy Active Member

    Messages:
    574
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    70
    #9
    They're not trying to rip you off. I'm confident that if you payed somebody to design a form for you, it would be much more advanced and sleek than a basic <form>. But as others have said, there are many free scripts, plugins, etc. out there that will suffice for what you're needing.
     
    Piggy, Apr 17, 2010 IP