# PHP Contact Form - Layout and special characters problems

**URL:** <https://forum.kirupa.com/t/php-contact-form-layout-and-special-characters-problems/232288>\
**Category:** programming\
**Created:** [July 12, 2007, 2:03pm UTC](https://forum.kirupa.com/t/php-contact-form-layout-and-special-characters-problems/232288 "2007-07-12T14:03:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![4lex](https://avatars.discourse-cdn.com/v4/letter/4/c68b51/32.png) [@4lex](https://forum.kirupa.com/u/4lex)\
**Post date:** [July 12, 2007, 2:03pm UTC](https://forum.kirupa.com/t/php-contact-form-layout-and-special-characters-problems/232288/1 "2007-07-12T14:03:33Z")

</div>

Hello Kirupan people.

I followed this tutorial [http://www.kirupa.com/web/php\_contact\_form.htm](http://www.kirupa.com/forum/../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

<?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
