All pastes #984145 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-04-13 23:27 UTC
rendered paste body
<?
$email_to = "rick@f0c.com";
$success_message = "Thanks for contacting us!";

function showform($message = NULL,$data){
$formstuff =<<<END
$message<br>
<form method="post" action="">
    <div id="name_field"><label for="name">Name</label> <input type="text" id="name" name="contact[name]" value="$data[name]" /></div>
    <div id="email_field"><label for="email">Email</label> <input type="text" id="email" name="contact[email]" value="$data[email]" /></div>
                <div id="subject_field"><label for="subject">Message subject</label> <input type="text" id="contact[subject]" name="contact[subject]" value="$data[subject]" /></div>
    
    <div id="message_field"><label for="message">Message details</label> <textarea id="message" name="contact[body]" rows="8" cols="45">$data[body]</textarea></div>
    <p id="submit_field"><button class="submit">Go ahead, we won't bite &raquo;</button></p>
</form>
END;
	echo $formstuff;
}

if(isset($_POST['contact'])){
	$contact = $_POST['contact'];
	if($contact['email']==""){
		showform("Please put in your email address!",$contact);
	}elseif ($contact['name']==""){
		showform("Please put in your name!",$contact);
	}elseif ($contact['subject']==""){
		showform("Please put in a subject!",$contact);
	}elseif ($contact['subject']==""){
		showform("Please put in a subject!",$contact);
	}elseif ($contact['body']==""){
		showform("Please fill in the message!",$contact);
	}else{
		$message = "From: $contact[name]\r\n";
		$message .= "Email: $contact[email]\r\n";
		$message .= "Message:\r\n\r\n$contact[body]";
		$subject = "Site Contact: $contact[subject]";

		$headers = "From: $contact[email]\r\n";
		$headers .= "Reply-To: $contact[email]\r\n";
		mail($email_to,$subject,$message,$headers);
		
		//sent, show the success message
		echo $success_message;
	}
}else{
	showform();
}
?>