Hello Kirupan people.
I followed this tutorial http://www.kirupa.com/web/php_contact_form.htm and it works great. However, I’m having a few problems with the layout and special characters such as ç, á, â, ã and so on.
Here is my code:
<?php
if(isset($_POST['submit'])) {
$to = "myemail@myserver.com";
$subject = "My Contact Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
if(empty($_POST['name'])) {
echo '*You must fill in the <b>Name</b> field!<br>';
} else {
}
if(empty($_POST['message'])) {
echo '*You must fill in the <b>Message</b> field!<br>';
} else {
}
if (!eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
echo '*You must insert a valid <b>e-mail</b> address!';
exit;
}
$body = "From: $name_field
E-Mail: $email_field
------------------------------------------------------------------------------------
Message:
$message";
echo "Thanks for contacting us. Your message has been sent <b>$to!</b>";
mail($to, $subject, $body);
} else {
echo "blargh";
}
?>
Well, the layout problem is that I want the error messages to be printed out on the same page (contact.php). I managed to do that by inserting an include function <?php include( ‘mailer.php’ ); ?> in the contact page, but when the script hits the line exit; everything that’s bellow it is not displayed, like the page footer. I tried deleting it from the code but then it’ll also print out the “Thanks for contacting us…” message. How can I solve this little problem?
Regarding special characters, I tried inserting headers into the code such as:
$headers = "MIME-Version: 1.0
";
$headers .= "Content-type: text/plain; charset=UTF-8
";
Didn’t work thou, how can this email form handle special characters?
Thanks!
Alex