Jump to content

PHP Contact Us form


jha900

Recommended Posts

Header won't work since his form displays output.  HTML or javascript would be the best way.

 

How do you know if the form displays output?  Did you mean errors and warnings if invalid input is entered?

 

Try putting this on the very top of the page:

if(!isset($_POST['submit'])) {
    
    // first validate the form	
    // then save the form in the database.

    if( form validates without errors) {
header ("Location:  http://" . $_SERVER['HTTP_HOST']);
	exit();
    }
}

Link to comment
https://forums.phpfreaks.com/topic/109948-php-contact-us-form/#findComment-564220
Share on other sites

Here's how I do mine. You may be able to use it just fine:

<form method="POST" action="p_contact.php">
			<center>
				<h3>Contact Us</h3>
			<table border="0">
				<tr>
					<td>Your Name:</td>
					<td><input type="text" name="name" size="56"></td>
				</tr>
				<tr>
					<td>E-Mail Address:</td>
					<td><input type="text" name="email" size="56"></td>
				</tr>
				<tr>
					<td>Contact Reason:</td>
					<td><select name="reason">
					    <option value="1" selected="selected">Need assistance with a script you made</option>
					    <option value="2">Need Assistance with a script I made</option>
					    <option value="3">Looking for help with an open-source project</option>
					    <option value="4">Wanted to thank you for all you've done</option>
					    <option value="5">Offering assistance with one of your open-source projects</option>
					    <option value="6">Just saying "Hi"/Other</option>
					    </select>
					    </td>
				</tr>
				<tr>
					<td>Subject:</td>
					<td><input type="text" name="subject" size="56"></td>
				</tr>
				<tr>
					<td>Message:</td>
					<td><textarea name="body" cols="42" rows="10"></textarea></td>
				</tr>
				<tr>
					<td> </td>
					<td><input type="submit" value="Submit"></td>
				</tr>
			</table>
</form>

and my p_contact.php page:

<?php
$reason_array = array("Need assistance with a script you made", "Need Assistance with a script I made", "Looking for help with an open-source project", "Wanted to thank you for all you've done", "Offering assistance with one of your open-source projects", "Just saying \"Hi\"/Other");
$reason = $_POST['reason'];
$contact_reason = $reason_array[$reason -1];
$subject = $_POST['subject'];
$body = $_POST['body'];
$email = $_POST['email'];
$name = $_POST['name'];
$to = "[email protected]";
$subject = $_POST['subject'];
$message = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html>
<head>
<title>".$subject."</title>
</head><center>Contact Reason: $contact_reason</center><br />\n
<strong>Name:</strong>$name<br />\n";
$message_clean1 = str_replace("\'", "'", $_POST['body']);
$message_clean2 = str_replace('"', "'", $message_clean1);
$message_clean3 = str_replace("\v", "", $message_clean2);
$message_clean4 = str_replace("\'", "'", $message_clean3);
$message .= $message_clean4;
$message .= "<br /><br /><br />";
$message .= "\n</body></html>";
include("MIME.class.php");
$mime = new MIME_mail($email, $to, $subject);
$mime->attach($message, "", HTML, BASE64);
$mime->send_mail();
header("location:contact_us.php");
exit();
?>

*Edit

forgot. Mine uses the Mime mail class. If you want to use my method, you'll need to get that from PHPGuru.org.

Link to comment
https://forums.phpfreaks.com/topic/109948-php-contact-us-form/#findComment-564226
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.