1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Looking for a basic contact form code/solution

Discussion in 'HTML & Website Design' started by pipes, Jan 21, 2009.

  1. #1
    Hello, im looking for a suggestion or the code neccessary to place a basic contact form onto an html page.

    Nothing fancy, doesn't need tons of form fields, and something that doesn't require linking back to the developer.

    The easier to add the better, free also.
     
    pipes, Jan 21, 2009 IP
  2. kjmcculloch

    kjmcculloch Well-Known Member

    Messages:
    850
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    108
    #2
    The best way to do this would be by an HTML form sending information to a PHP script which would then send you an email.

    If you want to do this and need further help or a script just PM me.
     
    kjmcculloch, Jan 21, 2009 IP
  3. revoD

    revoD Peon

    Messages:
    120
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Use this tool: phpformgen.sourceforge.net

    It allows you to create your form on the web, then save out the code and files to add to your html page.
     
    revoD, Jan 21, 2009 IP
  4. SiteTalkZone

    SiteTalkZone Peon

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here is my version:

    Process.php

    
    
    <?php
    session_start();
    include("validate.php");
    // *********************************************************
    // Perform server side validation of vital inputted information.
    // *********************************************************
    if(!$_POST['name'] or trim($_POST['name']) == '' )
    { $_SESSION['var_errors'][] = 'Username not provided'; }
    if(!$_POST['email'] or trim($_POST['email']) == '' )
    { $_SESSION['var_errors'][] = 'Please provide an email address'; }
    
    $result = checkemail($_POST['email']);
    if ($result != 1) $_SESSION['var_errors'][] = $result;
    
    if(isset($_SESSION['var_errors'])){
    	header("Location: inquiries.php");
    }
    else{
    	// **************************
    	// Set up variables for mailer
    	// ************************** 
    	$to = 'youremail@yourdomain.com'; // Address to send messege to.
    	$subject = $_POST['subject'];
    	$message = $_POST['detail'];
    	$mail_from = $_POST['email'];
    	$header="From: ". $_POST['name'] . " <" . $_POST['email']. ">\r\n";;
    
    	// **************************
    	// Send Messege
    	// **************************
    	$result = mail($to,$subject,$message,$header);
    	
    	// **************************
    	// Check mailer result.
    	// **************************
    	if($result){
    		$_SESSION['CONFIRM'] = "Thanks, We've recived your contact information and your message and will get back to you shortly. <a href='index.php'>Home</a>";
    		header("Location: confirm.php");
    	}else{
    		$_SESSION['var_errors'][] = 'The mailer encountered an error, your messege was not sent, if you cannot 
    		get past this error and need to contact us you can send a e-mail directly to youremail@yourdomain.com';
    		header("Location: inquiries.php");
    	}
    }
    ?>
    
    
    PHP:

    Enquiry.php
    
    
    <?php
    	session_start();
    	include("elements.php");
    	head();
    	pgTop();
    ?>
    		<!-- Main Body -->	
    		<div id="main" >	
    			<?php if (isset($_SESSION['var_errors'])) {	?> 
    				<span class="errors">
    				Result: <br />
    					<?php 
    							foreach ($_SESSION['var_errors'] as $error){ print $error . '<br />'; } }
    							unset($_SESSION['var_errors']); // Delete error info  
    					?>
    				</span>
    
    			<h2>Packages:</h2>
    			
    			<fieldset>
    				<form method="post" action="process.php">
    					
    					<label>Name:</label><br />
    					<input name="name" type="text" id="name" size="50"><br />
    
    					<label>Email:</label><br />
    					<input name="email" type="text" id="email" size="50"><br />
    				
    					<label>Subject</label><br />
    					<input name="subject" type="text" id="subject" size="50"><br />
    
    					<label>Messege:</label><br />
    					<textarea name="detail" cols="50" rows="4" id="detail"></textarea><br />
    
    					<input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset">
    				</form>
    			</fieldset>
    			
    		</div>
    		<!-- /Main Body -->		
    <?footer();?>
    
    HTML:
    Confirm.php

    
    <?php
    	session_start();
    	
    	if (isset($_SESSION['CONFIRM'])){
    	include("elements.php");
    	head();
    	pgTop();
    	
    ?>
    		<!-- Main Body -->	
    		<div id="main" >	
    				<span class="errors">
    					<p><?php echo $_SESSION['CONFIRM']; unset($_SESSION['CONFIRM']); ?></p>
    				</span>	
    		</div>
    		<!-- /Main Body -->		
    <?php
    	footer();
    }else{
    	header("Location: index.php");
    }
    ?>
    
    
    PHP:
    Check E-mail function from my validate.php
     --------------------------------------------------------------------------------------------
    // Function: checkemail.
    // Abstract: Validates a submitted e-mail address.
    // Arguments: Takes one argument, the email address as a string $emai
    // --------------------------------------------------------------------------------------------
    function checkemail($email)
    {
    	$email = trim($email);
    	
    	// Check address is present. 
    	if(empty($email))
    		return ("No email address provided to validate.");
    	
    	$validsyntax  =   "^[0-9a-z~!#$%&_-]([.]?[0-9a-z~!#$%&_-])*" .
    					  "@[0-9a-z~!#$%&_-]([.]?[0-9a-z~!#$%&_-])*$";
    					  
    	if(!eregi($validsyntax, $email)) // Check the syntax of the address.
    		return ("Invalid E-mail address: address must be in 'name@domain' format.");
    	elseif(strlen($email) > 40)  	 // Check the legnth of the address.
    		return ("Invalid E-mail address: address cannot by over 40 characters.");
    	
    	return true;
    }
    
    PHP:
    You can see this in action on traffichead.net, dont start sending me loads of messages to test it though. :p

    Of course you need to style the form elements using CSS to make it look alright.

    Take from my post here: http://www.sitetalkzone.com/showthread.php?p=11618#post11618
     
    SiteTalkZone, Jan 21, 2009 IP
    pipes likes this.
  5. pipes

    pipes Prominent Member

    Messages:
    12,766
    Likes Received:
    958
    Best Answers:
    0
    Trophy Points:
    360
    #5
    SiteTalkZone, thanks very much for providing the code, thats the sort of result that im looking for, a nice basic form.

    Much appreciated.

    Actually im a bit confused with that, im not sure about the certain parts that i need to edit. :eek:
     
    pipes, Jan 21, 2009 IP
  6. SiteTalkZone

    SiteTalkZone Peon

    Messages:
    243
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hey if you want any help I'm always around do you have an instant messenger? MSN/AIM or Skype? PM me your IM handle if you need help.
     
    SiteTalkZone, Jan 21, 2009 IP