PHP contact form problem

5 pts.
Tags:
PHP
PHP contact form
Web development
Hello, I have a PHP contact form on my website which was working for a few year up until now. When I try to submit a test message using the contact form, it clears the form and looks as though the page doesn't direct me to my "thank you" page, nor does the message get sent. Can someone please tell me what's wrong with my code?: <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" /> <META CONTENT="document" NAME="resource-type"> <META CONTENT="global" NAME="distribution"> <link href="stylesheet.css" rel="stylesheet" type="text/css"> </head> <body> <div align="center"> <table width="710" border="0" cellpadding="5"> <?php include("includes/top_menu_e.inc"); ?> <tr valign="top"> <td colspan="4"> <h2> Contact Us</h2> <?php // emailing code starts here // DO NOT EDIT FROM HERE TO LINE 127 // This code sends the email // Where it is possible to edit the code I have indicated function is_email_valid($email) { if(eregi("^[a-z0-9._-]+@+[a-z0-9._-]+.+[a-z]{2,3}$", $email)) return TRUE; else return FALSE; } if ($submit) { if (!$email || !$firstname || !$lastname || !$message) { $error = "Sorry, you need to fill in all the fields."; } elseif (!is_email_valid($email)) //bad email message { $error = "Sorry, that email is not valid."; } else { // to change where the email is sent edit the email address below $recipient = "myemail@myemail.com"; // testing $recipient = "myemail@myemail.com"; $subject = "Message from $firstname $lastname"; $message ="$message ------------------ First: $firstname Lastname: $lastname Email: $email "; $headers = "From: $firstname $lastname <$email>n"; $headers .= "X-Sender: $firstname $lastname <$email>n"; $headers .= "X-Mailer: PHPn"; // mailer $headers .= "Return-Path: <$email>"; // Return path for errors $headers .= "Content-Type: text/plain; charset=Shift_JIS"; // Mime type // and now mail it mail($recipient, $subject, $message, $headers); // thank you message // editing the following text OK ?> Thanks for getting in touch. We'll try to reply as soon as possible. <p> Continue to the <a href ="index.php">home page.</a> <?php }} if (!$submit || $error) { //display form if (isset($HTTP_POST_VARS)){ while(list($var, $val) = each($HTTP_POST_VARS)){ if (empty($val)){ $bad[$var] = 1; } } } if ($error) echo "<i><b><font color = "red">".$error."</font></b></i>"; ?> <p>Tel: 090-9286-1216 <br> Email: <a href="mailto:myemail@myemail.com">myemail@myemail.com</a></p> <p>Or send a message with the form below. <em>(Please write in English).</em></p> <a name="more"></a> <form name="form1" id="form1" method="post" action="contact.php"> <table width="100%" border="0" cellspacing="1" cellpadding="5"> <tr> <td> </td> <td> </td> </tr> <tr> <td><?php if (isset($bad['firstname'])){ echo "<FONT COLOR=FF0000>"; } ?> First Name <?php if (isset($bad['firstname'])){ echo "</FONT>"; } ?> </td> <td><input name="firstname" type="text" id="firstname" value="<?php echo $firstname; ?>"></td> </tr> <tr> <td><?php if (isset($bad['lastname'])){ echo "<FONT COLOR=FF0000>"; } ?> Last Name <?php if (isset($bad['lastname'])){ echo "</FONT>"; } ?> </td> <td><input name="lastname" type="text" id="lastname" value="<?php echo $lastname; ?>"></td> </tr> <tr> <td><?php if (isset($bad['email'])){ echo "<FONT COLOR=FF0000>"; } ?> Email <?php if (isset($bad['email'])){ echo "</FONT>"; } ?> </td> <td><input name="email" type="text" id="email" value="<?php echo $email; ?>"></td> </tr> <tr> <td><?php if (isset($bad['message'])){ echo "<FONT COLOR=FF0000>"; } ?> Message <?php if (isset($bad['message'])){ echo "</FONT>"; } ?> </td> <td><textarea name="message" cols="50" rows="5" id="message" value="<?php echo $message; ?>"></textarea></td> </tr> <tr> <td> </td> <td><input name="submit" type="submit" id="submit" value="Send message"></td> </tr> </table></form> <?php } // emailing code ends here ?> </td> <td> <p> <?php include("includes/property_rent.inc"); ?> </p> <p> <?php include("includes/property_sale.inc"); ?> </p> <p> <?php include("includes/sub_menu.inc"); ?> </p></td> </tr> <tr> <td><img src="images/spacer.gif" width="100" height="1" /></td> <td><img src="images/spacer.gif" width="8" height="1" /></td> <td><img src="images/spacer.gif" width="8" height="1" /></td> <td><img src="images/spacer.gif" width="350" height="1" /></td> <td><img src="images/spacer.gif" width="150" height="1" /></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td><div align="center"><?php include("includes/footer_e.inc"); ?></div></td> <td> </td> </tr> <tr> <td colspan="5"></td> </tr> </table> </div> </body> </html>

Answer Wiki

Thanks. We'll let you know when a new response is added.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following