Page not found

i just created a contact form. after i submit the contact form, hoping it would echo "<p>Your email has been sent.</p>"
the URL shows http://www.xxxxxxx/contact.php?status=sent
however, there is the error code 404, page not found.
index.php
Zoe ZoeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Trenton KnewOwner / Computer WhispererCommented:
instead of this
		<?php
			if(isset($_GET['status']) && $_GET['status'] == "sent"){ ?>
				<p>Your email has been sent.</p>
			<?php }else{ ?>

Open in new window

try including "echo" and keeping it all in the statement?
		<?php
			if(isset($_GET['status']) && $_GET['status'] == "sent"){ 
				echo <p>Your email has been sent.</p>
			php }else{ ?>

Open in new window


also, get rid of the ?> and following <?php immediately after, there's nothing between them, so why close and open?
0
hieloCommented:
"or" should be  "||" (two pipes), not one:
if($name == "" || $email == "" || $message == "")

Also, the code above posts to itself, so the redirection need to be to itself so you can see the message.  Save this as "test.php" and try it:
<?php
require_once('../inc/path.php'); 

	if($_SERVER['REQUEST_METHOD'] == POST){
		$name = trim($_POST['name']);
		$email = trim($_POST['email']);
		$message = trim($_POST['message']);

		if($name == "" || $email == "" || $message == "") {
			$error_msg = "Please enter your name and email address and message to send the mail.";
		}

		if(!isset($error_msg)) {
			foreach( $_POST as $value ){
	    		if( stripos($value,'Content-Type:') !== FALSE ){
	      			$error_msg = "There was a problem with the information you have entered.";
	     		}
			}
		}

		if(!isset($error_msg) && $_POST['address'] != ""){
			$error_msg = "Your form submission has an error.";
		}

		require_once(ROOT_PATH .'inc/phpmailer/class.phpmailer.php');
		$mail = new PHPMAILER;
		if(!isset($error_msg) && !$mail -> ValidateAddress($email)) {
			$error_msg = "You must enter a valid email address.";
		}

		$email_body ="";
		$email_body .= "Name: " . $name . "<br>";
		$email_body .= "Email: " . $email . "<br>";
		$email_body .= "Message: " . $message;

		$mail->SetFrom($email, $name);

		$address = "shzoechen@gmail.com";
		$mail->AddAddress($address, "Mike 4 Shirts");

		$mail->Subject    = "Mike 4 Shirts Contact Form | " . $name;

		$mail->MsgHTML($email_body);

		if(!isset($error_msg)) {
			if($mail->Send()) {
				header('Location:'. $_SERVER['SCRIPT_NAME'] . '?status=sent');
				exit();
			} else {
		  		$error_msg = "There is an error to send this email. ";
			}
		}

	}
$page_title = "Contact Mike";
$section = "contact";
include(ROOT_PATH . 'inc/header.php'); 
?>
<div class="section page">
	<div class="wrapper">
		<h1>contact</h1>

		<?php
			if(isset($_GET['status']) && $_GET['status'] == "sent"){ ?>
				<p>Your email has been sent.</p>
			<?php 
			}else{ 
			?>

				<?php if(isset($error_msg)) {
					echo '<p class="message">' . $error_msg . '</p>';
				} else {
					echo '<p>I&rsquo;d like to hear from you! Complete the form to send me email.</p>';
				} ?>
				
				<form method="POST" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
					<table>
						<tr>
							<th>
								<label for="name">Name</label>
							</th>
							<td>
								<input type="text" name="name" id="name" value="<?php if(isset($name)) echo htmlspecialchars($name); ?>">
							</td>
						</tr>
						<tr>
							<th>
								<label for="email">Email</label>
							</th>
							<td>
								<input type="text" name="email" id="email" value="<?php if(isset($email)) echo htmlspecialchars($email); ?>">
							</td>
						</tr>
						<tr>
							<th>
								<label for="message">Message</label>
							</th>
							<td>
								<textarea name="message" id="message"><?php if(isset($message)) echo htmlspecialchars($message); ?></textarea>
							</td>
						</tr>
						<tr style = "display: none">
							<th>
								<label for="address">Address</label>
							</th>
							<td>
								<textarea name="address" id="address"></textarea>
								<p>Human do not need to enter.</p>
							</td>
						</tr>
					</table>
					<input type="submit" name="submit" id="submit" value="send">
				</form>
			<?php }
		?>

	</div>
</div>

<?php include(ROOT_PATH . 'inc/footer.php'); ?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Zoe ZoeAuthor Commented:
Thank you hielo. You got the problem. I changed the file name from contact.php to contact/index.php :P
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.