Location: PHPKode > scripts > Lexperts Contact Form > lexperts-contact-form/contact_form.php
<?php

// CONFIG YOUR E-MAIL
define('SEND_TO', 'hide@address.com');
define('SUBJECTS', 'Subject 1, Subject 2, Subject 3');
define('SUCCESS_MESSAGE', 'Thank you {name}.');
define('INBOX_MESSAGE', 'Name: {name} {enter} Company: {company} {enter} E-mail: {email} {enter} Phone number: {phone} {enter} Subject: {subject} {enter} Comment: {enter} {comment}');


// CONFIG YOUR ERROR MESSAGES
define('ERROR_MESSAGE_NAME', '(Name can\'t be blank)');
define('ERROR_MESSAGE_EMAIL', '(E-mail can\'t be blank)');
define('ERROR_MESSAGE_EMAIL_INVALID', '(Email is invalid)');
define('ERROR_MESSAGE_PHONE_INVALID', '(Phone is invalid)');
define('ERROR_MESSAGE_SUBJECT', '(Subject can\'t be blank)');
define('ERROR_MESSAGE_COMMENT', '(Your comment can\'t be blank)');
define('ERROR_MESSAGE_CAPTCHA', '(Verification code can\'t be blank)');
define('ERROR_MESSAGE_CAPTCHA_INVALID', '(Verification code is invalid)');


// DON'T TOUCH BEGIN
@ini_set('session.use_cookies', '1');
@ini_set('session.use_trans_sid', 'false');
	
@session_set_cookie_params(0, '/');
@session_start();

if (ini_get('register_globals')) {
	$globals = array('_SESSION');

	foreach ($globals as $global) {
		foreach ($GLOBALS[$global] as $key => $value) {
			if ($value === @$GLOBALS[$key]) {
				unset($GLOBALS[$key]);
			}
		}
	}
}

@ini_set('magic_quotes_gpc', 'Off');

if (ini_get('magic_quotes_gpc')) {
	function clean($data) {
   		if (is_array($data)) {
  			foreach ($data as $key => $value) {
    			$data[$key] = clean($value);
  			}
		} else {
  			$data = stripslashes($data);
		}
		return $data;
	}			
	$_POST = clean($_POST);
}

function php_self(){
	if(isset($_SERVER['PATH_INFO']) && strlen($_SERVER['PATH_INFO'])> 0){
		return substr($_SERVER['PHP_SELF'], 0, (strlen($_SERVER['PHP_SELF']) - @strlen($_SERVER['PATH_INFO'])));
	}else{
    	return $_SERVER['PHP_SELF'];
	}
}

$subjects = explode(',', SUBJECTS);

$error					= FALSE;
$send 					= FALSE;

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

	$name    			= $_POST['name'];
	$company    		= $_POST['company'];
	$email   			= $_POST['email'];
	$phone   			= $_POST['phone'];
	$subject 			= $_POST['subject'];
	$comment			= $_POST['comment'];
	$captcha			= $_POST['captcha'];
		
	$pfind = array(
	  			'+',
				'-',
				' '
			);
			
	$phone_check = str_replace($pfind, '', $phone);
	
	if(empty($name)){
		$error_name 	= ERROR_MESSAGE_NAME;
		$error 			= TRUE;	
	}
	
	if(empty($email)){
		$error_email    = ERROR_MESSAGE_EMAIL;
		$error 			= TRUE;	
	}elseif(!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', $email)){
		$error_email    = ERROR_MESSAGE_EMAIL_INVALID;
		$error 			= TRUE;
	}
	
	if(!empty($phone)){
		if(!ctype_digit($phone_check)){
			$error_phone   	= ERROR_MESSAGE_PHONE_INVALID;
			$error 			= TRUE;
		}
	}
	
	if(empty($subject)){
		$error_subject  = ERROR_MESSAGE_SUBJECT;
		$error 			= TRUE;	
	}
	
	if(empty($comment)){
		$error_comment  = ERROR_MESSAGE_COMMENT;
		$error 			= TRUE;	
	}
	
	if(empty($captcha)){
		$error_captcha  = ERROR_MESSAGE_CAPTCHA;
		$error 			= TRUE;	
	}elseif($_SESSION['captcha'] != $captcha){
		$error_captcha  = ERROR_MESSAGE_CAPTCHA_INVALID;
		$error 			= TRUE;
	}
	
	if(!$error) {
	
		if(strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) { 
      		$ent 		= "\r\n"; 
    	}elseif(strtoupper(substr(PHP_OS, 0, 3) == 'MAC')) { 
      		$ent 		= "\r"; 
    	}else{ 
     		$ent 		= "\n"; 
    	}
		
		$find = array(
	  			'{name}',
	  			'{company}',
				'{email}',
				'{phone}',
	  			'{subject}',
	  			'{comment}',
	  			'{enter}'
			);
	
		$replace = array(
	  			'name' 		=> $name,
				'company' 	=> $company,
				'email' 	=> $email,
				'phone' 	=> $phone,
	  			'subject'   => $subject,
	  			'commment'  => $comment,
	  			'enter'		=> $ent
			);
			
		$comment = str_replace($find, $replace, INBOX_MESSAGE);
	
		$boundary 		= '----=_NextPart_' . md5(rand());  
	    	
		$headers  		= 'From: ' . $name . '<' . $email . '>' . $ent; 
    	$headers 	   .= 'X-Mailer: PHP/' . phpversion() . $ent;  
    	$headers 	   .= 'MIME-Version: 1.0' . $ent; 
    	$headers 	   .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . $ent . $ent;  
	
		$message  		= '--' . $boundary . $ent;  
		$message 	   .= 'Content-Type: text/plain; charset="utf-8"' . $ent; 
		$message 	   .= 'Content-Transfer-Encoding: base64' . $ent . $ent;
    	$message 	   .= chunk_split(base64_encode($comment));
		
		ini_set('sendmail_from', $email);
		
    	mail(SEND_TO, $subject, strip_tags(html_entity_decode($message)), $headers);  
		
		$send 			= TRUE;
		$success 		= str_replace($find, $replace, SUCCESS_MESSAGE);
	}
}
// DON'T TOUCH END

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" xml:lang="en">
<head>
<title>Lexperts Contact Form</title>
<meta name="description" content="Lexperts Contact Form" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>

<div id="box">

<? if($send){ ?>

<div id="success"><h1>Email Sent Successfully.</h1><p><?=$success; ?></p></div>

<? }else{ ?>

	<div id="form">

		<? if($error) { ?><div class="error"><h1>Invalid Form Input</h1></div><? } ?>

		<form  method="post" action="<?=php_self() ?>">

			<label for="name"><span class="required">*</span> Your Name 
				<? if(!empty($error_name)) { ?>
					<span class="error_message"><?=$error_name ?></span>
				<? }elseif(!empty($name)){ ?>
					<img src="image/icon/accept.png" />
				<? } ?>
			</label>
			<input name="name" type="text" id="name" size="30" <? if(!empty($name)){ ?> value="<?=$name ?>" <? } ?> class="text-input" />
			
			<label for="company">Company 
				<? if(!empty($error_company)) { ?>
					<span class="error_message"><?=$error_company?></span>
				<? }elseif(!empty($company)){ ?>
					<img src="image/icon/accept.png" />
				<? } ?>
			</label>
			<input name="company" type="text" id="company" size="30" <? if(!empty($company)){ ?> value="<?=$company ?>" <? } ?> class="text-input" />
	
	
	    	<label for="email"><span class="required">*</span> Email 
    	   		<? if(!empty($error_email)) { ?>
    	   			<span class="error_message"><?=$error_email ?></span>
    	   		<? } elseif(!empty($email)){ ?>
    	   			<img src="image/icon/accept.png" />
    	   		<? } ?>
    	   	</label>
	    	<input name="email" type="text" id="email" size="30" <? if(!empty($email)){ ?> value="<?=$email ?>" <? } ?> class="text-input" />
			
			
			<label for="phone">Phone number 
				<? if(!empty($error_phone)) {?>
					<span class="error_message"><?=$error_phone?></span>
				<? }elseif(!empty($phone)){ ?>
					<img src="image/icon/accept.png" />
				<? } ?>
			</label>
			<input name="phone" type="text" id="phone" size="30" <? if(!empty($phone)){ ?> value="<?=$phone ?>"<? } ?> class="text-input" />


	    	<label for="subject"><span class="required">*</span> Subject 
	    		<? if(!empty($error_subject)) { ?>
	    			<span class="error_message"><?=$error_subject ?></span>
	    		<? } elseif(!empty($subject)){ ?>
	    			<img src="image/icon/accept.png" />
	    		<? } ?>
	    	</label>
    	    <select name="subject" type="text" id="subject">
	    		<? foreach($subjects as $value) { ?>
	    			<option value="<?=$value ?>"><?=$value ?></option>
	    		<? } ?>
    		</select>
    
    
    		<label for="comment"><span class="required">*</span> Your comment 
    			<? if(!empty($error_comment)) { ?>
    				<span class="error_message"><?=$error_comment ?></span>
    			<? }elseif(!empty($comment)){ ?>
    				<img src="image/icon/accept.png" />
    			<? } ?>
    		</label>
    		<textarea name="comment" id="comment" rows="8"><? if(!empty($comment)){ echo $comment; } ?>
</textarea>
    		
    		
    		<label for="captcha"><span class="required">*</span> Are you human? 
    			<? if(!empty($error_captcha)) { ?>
    				<span class="error_message"><?=$error_captcha ?></span>
    			<? } ?>
    		</label>
    		<div class="captcha"><img src="captcha.php" /></div> 
    		<input name="captcha" type="text" id="captcha" size="30" class="text-input-captcha" />
    		<br />
    		<input type="submit" class="submit" value="Send" />
  
		</form>

	</div>

<? } ?>

</div>
</body>
</html>
Return current item: Lexperts Contact Form