Hi guys! I´m really new to PHP, but i'm involved in a small project. But i'm having an issue with the mail form. It was working, but as the user refreshed the page it would send the values of the variables again and again...
First i managed to auto refresh the page when submiting the values, and it worked. But that means that if the page has a lot of content it will tale always alot of time to refresh.
So i tried to split the code in two. With index.php and mess.php. index.php contais the form, wich than sends the values to mess.php, processing the values and returning to index.php. But i have validations working on mess.php and i want to show them on index.php when this page refreshes. But i can't seem to make it. I've tried everything and searched every post!I need some help please...

Here's the two pages:

index.php
This contains the form and the variable &sucesso, wich will be filled and displayed with the validation messages in variable &sucesso in mess.php.

<p class="copyright">© <?php echo date("Y"); ?> AroundField. Todos os direitos reservados. Design by <a href="http://www.ideal-line.pt">Ideal Line</a>.</p>
    </div>
    <p class="villaPT"><a>Villa Portucalle - Traditional Food & Arts Trading Company</a></p>
  </div>

  <div id="form">
    <?=$sucesso?>
    <h4>Deseja ser contactado(a)?</h4>
    <form action="mess.php" method="post">
      <p><label for="nome">Nome</label> <input type="text" name="nome" id="nome" value="<?=$_SESSION['nome']?>"/></p>
      <p><label for="email">Email <span class="error">*</span></label> <input type="text" name="email" id="email" value="<?=$_SESSION['email']?>"/></p>
      <p><textarea name="conteudo" id="conteudo"><?=$_SESSION['conteudo']?></textarea></p>
      <p><input type="submit" name="enviar" value="enviar »" /></p>
      <input type='hidden' value='1' name='submitted' />
    </form>
  </div>

</div>

</body>
</html>

mess.php
This contais the PHP with validation messages within a variable($sucesso)wich i need to send to $sucesso in index.php after validation

<?php
function is_email($email) {
		eregi("^([0-9a-zA-Z]+)([.,_]([0-9a-zA-Z]+))*[@]([0-9a-zA-Z]+)([.-]([0-9a-zA-Z]+))*[.]([0-9a-zA-Z]){2}([0-9a-zA-Z])?$",$email,$match);
		list($email_comp ,$login, $domain, $sufixies) = $match;
		if ($email_comp == $email) {
			return true;
		} else {
			return false;
		}
	}

	// Prepare email to send
	if ($_POST['submitted']) {
		$para = "nuno.baixinho@epochmultimedia.com";  //info@aroundfield.pt
		$assunto = "contacto via website\r\n";
		$conteudo = $_POST['conteudo']."\r\n";
		$conteudo .= $_POST['nome']."\r\n";
		$conteudo .= $_POST['email']."\r\n";
		$header='MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n" . 'From: Website <no-reply@localhost>' . "\r\n";

		$_SESSION['nome'] = "";
		$_SESSION['email'] = "";
		$_SESSION['conteudo'] = "";
		$_SESSION['nome'] = $_POST['nome'];
		$_SESSION['email'] = $_POST['email'];
		$_SESSION['conteudo'] = $_POST['conteudo'];
		
				// Validate email and required fields
		
		if(!is_email($_POST['email']) || $_POST['email'] == "") {
			$erro2 = 1;
			$_SESSION['email'] = "";
			$sucesso= "<p class='alert error'><strong>(!)</strong> Introduza um email válido..</p>";
			header('Location: index.php');
						
		}
		if ($erro1 != 1 && $erro2 != 1) {
			if (mail($para, $assunto, $conteudo, $header)) {			   
			   $sucesso = "<p class='alert confirm'>Mensagem enviada!</p>";
			   header('Location: index.php');
			   
			 
			  $_SESSION['nome'] = "";
			  $_SESSION['email'] = "";
			  $_SESSION['conteudo'] = "";
			  
			} else {
			    $sucesso = "<p class='alert error'><strong>(!)</strong> Ocorreram erros..</p>";
				header('Location: index.php');
				
				
				
			
		    }
		}		
	}
	?>

Thanks!

Recommended Answers

All 12 Replies

im sorry but i've tried to use the file suplied with no success waiting 4 reply

Might be missing some code. Here´s the full code of both pages:

Index.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>AroundField | Sharing Portugal with the World</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="pt">
<--! <meta name="author" content="www.epochmultimedia.com - geral@epochmultimedia.com">
<meta name="copyright" content="2011 &copy; A. Morgado Gama">
<meta name="description" content="A. Morgado Gama - Página temporária">
<meta name="keywords" content="reabilitar, edifícios, construção, civil">

<link type="text/css" href="temas/clientside/geral.css" rel="stylesheet" media="screen" />
<!--[if IE]><link type="text/css" href="temas/clientside/IEstuff.css" rel="stylesheet" media="screen" /><![endif]-->

</head>

<body>

    <div id="container">

  <div id="header">
    <h1>AroundField</h1>
    <p>Sharing Portugal with the World</p>
  </div>

  <div class="content">
    <h2>Na Aroundfield acreditamos que o bom trabalho gera bons negócios. Este é o nosso compromisso. </h2>
    <h3>Ligar produtores e compradores numa base global, criando uma rede comercial que integra fornecimentos, marketing e transporte.</h3>
    <h3>Acompanhar todos os processos, sejam eles operacionais, logísticos ou aduaneiros, para que o seu produto chegue aos novos parceiros, nas melhores condições.</h3>
    <h4>Como?</h4>
    <p>Avaliação e preparação</p>
    <ul>
      <li>Avaliação da capacidade da empresa, e dos produtos oferecidos à exportação.</li>
      <li>Pesquisa de mercado.</li>
      <li>Auxílio na preparação do(s) produto(s) da empresa nacional para o mercado externo.</li>
      <li>Assessoria na adequação de embalagens, rótulos em língua estrangeira, etc.</li>
      <li>Auxílio na formação de preços para exportação.</li>
    </ul>
    <p>Promoção</p>
    <ul>
      <li>Selecção de possíveis países compradores.</li>
      <li>Apoio à elaboração de materiais promocionais, tais como site de Internet, panfletos explicativos, catálogos, etc.</li>
      <li>Captação de clientes no mercado externo.</li>
      <li>Envio de amostras para promoção do produto, consignação, participação em feiras e congressos.</li>
      <li>Suporte na negociação internacional.</li>
    </ul>
    <p>Execução</p>
    <ul>
      <li>Colaboração na estratégia de exportação, vendas e distribuição internacional.</li>
      <li>Preparação e organização de feiras, certames e mostras de produtos e serviços.</li>
      <li>Disponibilização de ferramenta e-commerce, para trocas comerciais online.</li>
      <li>Acompanhamento até ao destino final.</li>
    </ul>
  </div>

  <div id="footer">
    <div>
      <p class="company">AroundField Portuguese Trading Company Lda</p>
      <p class="address">
        Praceta Fernando Vale, 2A <br />
        1750-461 LISBOA, Portugal
      </p>
      <p class="contacts">
        Tel.:(+351) 210 992 871 <br />
        E.: info@aroundfield.pt
      </p>
      <p class="copyright">© <?php echo date("Y"); ?> AroundField. Todos os direitos reservados. Design by <a href="http://www.ideal-line.pt">Ideal Line</a>.</p>
    </div>
    <p class="villaPT"><a>Villa Portucalle - Traditional Food & Arts Trading Company</a></p>
  </div>

  <div id="form">
    <?=$sucesso?>
    <h4>Deseja ser contactado(a)?</h4>
    <form action="mess.php" method="post">
      <p><label for="nome">Nome</label> <input type="text" name="nome" id="nome" value="<?=$_SESSION['nome']?>"/></p>
      <p><label for="email">Email <span class="error">*</span></label> <input type="text" name="email" id="email" value="<?=$_SESSION['email']?>"/></p>
      <p><textarea name="conteudo" id="conteudo"><?=$_SESSION['conteudo']?></textarea></p>
      <p><input type="submit" name="enviar" value="enviar »" /></p>
      <input type='hidden' value='1' name='submitted' />
    </form>
  </div>

</div>

</body>
</html>

Mess.php:

<?php
function is_email($email) {
		eregi("^([0-9a-zA-Z]+)([.,_]([0-9a-zA-Z]+))*[@]([0-9a-zA-Z]+)([.-]([0-9a-zA-Z]+))*[.]([0-9a-zA-Z]){2}([0-9a-zA-Z])?$",$email,$match);
		list($email_comp ,$login, $domain, $sufixies) = $match;
		if ($email_comp == $email) {
			return true;
		} else {
			return false;
		}
	}

	// Prepare email to send
	if ($_POST['submitted']) {
		$para = "nuno.baixinho@epochmultimedia.com";  //info@aroundfield.pt
		$assunto = "contacto via website\r\n";
		$conteudo = $_POST['conteudo']."\r\n";
		$conteudo .= $_POST['nome']."\r\n";
		$conteudo .= $_POST['email']."\r\n";
		$header='MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n" . 'From: Website <no-reply@localhost>' . "\r\n";

		$_SESSION['nome'] = "";
		$_SESSION['email'] = "";
		$_SESSION['conteudo'] = "";
		$_SESSION['nome'] = $_POST['nome'];
		$_SESSION['email'] = $_POST['email'];
		$_SESSION['conteudo'] = $_POST['conteudo'];
		
				// Validate email and required fields
		
		if(!is_email($_POST['email']) || $_POST['email'] == "") {
			$erro2 = 1;
			$_SESSION['email'] = "";
			$sucesso= "<p class='alert error'><strong>(!)</strong> Introduza um email válido..</p>";
			header('Location: index.php');
						
		}
		if ($erro1 != 1 && $erro2 != 1) {
			if (mail($para, $assunto, $conteudo, $header)) {			   
			   $sucesso = "<p class='alert confirm'>Mensagem enviada!</p>";
			   header('Location: index.php');
			   
			 
			  $_SESSION['nome'] = "";
			  $_SESSION['email'] = "";
			  $_SESSION['conteudo'] = "";
			  
			} else {
			    $sucesso = "<p class='alert error'><strong>(!)</strong> Ocorreram erros..</p>";
				header('Location: index.php');
				
				
				
			
		    }
		}		
	}
	?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>AroundField | Sharing Portugal with the World</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="pt">
<meta name="author" content="www.epochmultimedia.com - geral@epochmultimedia.com">
<meta name="copyright" content="2011 &copy; A. Morgado Gama">
<meta name="description" content="A. Morgado Gama - Página temporária">
<meta name="keywords" content="reabilitar, edifícios, construção, civil">

<link type="text/css" href="temas/clientside/geral.css" rel="stylesheet" media="screen" />
<!--[if IE]><link type="text/css" href="temas/clientside/IEstuff.css" rel="stylesheet" media="screen" /><![endif]-->

</head>

<body>

</body>
</html>

That's it

Still does not work in any case I suggest you look at the following link and try to understand what the problem

the link

your code is working fine.......try to put your <?=$sucesso?> in SESSION VARIABLE.

$_SESSION= $successo;

call this $_SESSION not the $successo because your varibale become local to each page to make it global use $_SESSION;

NOTE: make sure your mess.php is in small letters not Mess.php

your code is working fine.......try to put your <?=$sucesso?> in SESSION VARIABLE.

$_SESSION= $successo;

call this $_SESSION not the $successo because your varibale become local to each page to make it global use $_SESSION;

Is this what you mean phpbeginners?

index.php:

<div id="form">
    [B]<?=$_SESSION['success'];?>[/B]
    <h4>Deseja ser contactado(a)?</h4>
    <form action="mess.php" method="post">
      <p><label for="nome">Nome</label> <input type="text" name="nome" id="nome" value="<?=$_SESSION['nome']?>"/></p>
      <p><label for="email">Email <span class="error">*</span></label> <input type="text" name="email" id="email" value="<?=$_SESSION['email']?>"/></p>
      <p><textarea name="conteudo" id="conteudo"><?=$_SESSION['conteudo']?></textarea></p>
      <p><input type="submit" name="enviar" value="enviar »" /></p>
      <input type='hidden' value='1' name='submitted' />
    </form>
  </div>

mess.php:

<?php
function is_email($email) {
		eregi("^([0-9a-zA-Z]+)([.,_]([0-9a-zA-Z]+))*[@]([0-9a-zA-Z]+)([.-]([0-9a-zA-Z]+))*[.]([0-9a-zA-Z]){2}([0-9a-zA-Z])?$",$email,$match);
		list($email_comp ,$login, $domain, $sufixies) = $match;
		if ($email_comp == $email) {
			return true;
		} else {
			return false;
		}
	}

	// Prepare email to send
	if ($_POST['submitted']) {
		$para = "nuno.baixinho@epochmultimedia.com";  //info@aroundfield.pt
		$assunto = "contacto via website\r\n";
		$conteudo = $_POST['conteudo']."\r\n";
		$conteudo .= $_POST['nome']."\r\n";
		$conteudo .= $_POST['email']."\r\n";
		$header='MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n" . 'From: Website <no-reply@localhost>' . "\r\n";

		$_SESSION['nome'] = "";
		$_SESSION['email'] = "";
		$_SESSION['conteudo'] = "";
		$_SESSION['nome'] = $_POST['nome'];
		$_SESSION['email'] = $_POST['email'];
		$_SESSION['conteudo'] = $_POST['conteudo'];
		[B]$_SESSION['success'] = $sucesso;[/B]

			// Validate email and required fields
		
		if(!is_email($_POST['email']) || $_POST['email'] == "") {
			$erro2 = 1;
			$_SESSION['email'] = "";
			header('Location: index.php');
			$sucesso= "<p class='alert error'><strong>(!)</strong> Introduza um email válido..</p>";			
						
		}
		if ($erro1 != 1 && $erro2 != 1) {
			if (mail($para, $assunto, $conteudo, $header)) {			   
			   header('Location: index.php');
			   [B]$sucesso = "<p class='alert confirm'>Mensagem enviada!</p>";[/B]			   
			   
			 
			  $_SESSION['nome'] = "";
			  $_SESSION['email'] = "";
			  $_SESSION['conteudo'] = "";
			  
			} else {
			    header('Location: index.php');
				$sucesso = "<p class='alert error'><strong>(!)</strong> Ocorreram erros..</p>";
				
				
				
				
			
		    }
		}		
	}
	?>

It's not workig. What am i doing wrong?

you forgot to put
<?php
session_start(); //every file must have this code
?>

if(!is_email($_POST['email']) || $_POST['email'] == "") {

			$erro2 = 1;
			$_SESSION['email'] = "";
			$sucesso= "<p class='alert error'><strong>(!)</strong> Introduza um email válido..</p>";
			$_SESSION['success']=$sucesso;//--------> PUT THIS
			header('Location: index.php');
						
		}
		if ($erro1 != 1 && $erro2 != 1) {

			if (mail($para, $assunto, $conteudo, $header)) {			   
			   $sucesso = "<p class='alert confirm'>Mensagem enviada!</p>";
			   $_SESSION['success']=$sucesso;//--------> PUT THIS
			   header('Location: index.php');
			   
			 
			  $_SESSION['nome'] = "";
			  $_SESSION['email'] = "";
			  $_SESSION['conteudo'] = "";
			  
			} else {
			    $sucesso = "<p class='alert error'><strong>(!)</strong> Ocorreram erros..</p>";
				$_SESSION['success']=$sucesso;//--------> PUT THIS
				header('Location: index.php');

Ok phpbeginners. I have tried this already. Still not working...

This is what i have now.

index.php:

<div id="form">
    <?=$_SESSION['success'];?>
    <h4>Deseja ser contactado(a)?</h4>
    <form action="mess.php" method="post">
      <p><label for="nome">Nome</label> <input type="text" name="nome" id="nome" value="<?=$_SESSION['nome']?>"/></p>
      <p><label for="email">Email <span class="error">*</span></label> <input type="text" name="email" id="email" value="<?=$_SESSION['email']?>"/></p>
      <p><textarea name="conteudo" id="conteudo"><?=$_SESSION['conteudo']?></textarea></p>
      <p><input type="submit" name="enviar" value="enviar »" /></p>
      <input type='hidden' value='1' name='submitted' />
    </form>

mess.php:

<?php
function is_email($email) {
        eregi("^([0-9a-zA-Z]+)([.,_]([0-9a-zA-Z]+))*[@]([0-9a-zA-Z]+)([.-]([0-9a-zA-Z]+))*[.]([0-9a-zA-Z]){2}([0-9a-zA-Z])?$",$email,$match);
        list($email_comp ,$login, $domain, $sufixies) = $match;
        if ($email_comp == $email) {
            return true;
        } else {
            return false;
        }
    }

    // Prepare email to send
    if ($_POST['submitted']) {
        $para = "nuno.baixinho@epochmultimedia.com";  //info@aroundfield.pt
        $assunto = "contacto via website\r\n";
        $conteudo = $_POST['conteudo']."\r\n";
        $conteudo .= $_POST['nome']."\r\n";
        $conteudo .= $_POST['email']."\r\n";
        $header='MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n" . 'From: Website <no-reply@localhost>' . "\r\n";

        $_SESSION['nome'] = "";
        $_SESSION['email'] = "";
        $_SESSION['conteudo'] = "";
        $_SESSION['nome'] = $_POST['nome'];
        $_SESSION['email'] = $_POST['email'];
        $_SESSION['conteudo'] = $_POST['conteudo'];
        $_SESSION['success'] = $sucesso;
        
                // Validate email and required fields
        
        if(!is_email($_POST['email']) || $_POST['email'] == "") {
            $erro2 = 1;
            $_SESSION['email'] = "";
            $sucesso= "<p class='alert error'><strong>(!)</strong> Introduza um email válido..</p>";
            $_SESSION['success']=$sucesso;                                
            header('Location: index.php');
            
                        
        }
        if ($erro1 != 1 && $erro2 != 1) {
            if (mail($para, $assunto, $conteudo, $header)) {               
              $_SESSION['nome'] = "";
              $_SESSION['email'] = "";
              $_SESSION['conteudo'] = "";
              $sucesso = "<p class='alert confirm'>Mensagem enviada!</p>";
              $_SESSION['success']=$sucesso;              
              header('Location: index.php');
              
              
            } else {
            
                $sucesso = "<p class='alert error'><strong>(!)</strong> Ocorreram erros..</p>";
                $_SESSION['success']=$sucesso;                                
                header('Location: index.php');
                
                                            
            }
        }        
    }
    ?>

Any ideas what might be the problem?

Thanks in advance

you did not read my instruction carefully.. :-) you forgot this one.
you forgot to put
<?php
session_start(); //every file must have this code PUT THIS ON TOP OF YOUR 2 FILES.
?>

index.php

<?php
session_start();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>AroundField | Sharing Portugal with the World</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="pt">
<--! <meta name="author" content="www.epochmultimedia.com - geral@epochmultimedia.com">
<meta name="copyright" content="2011 &copy; A. Morgado Gama">
<meta name="description" content="A. Morgado Gama - Página temporária">
<meta name="keywords" content="reabilitar, edifícios, construção, civil">

<link type="text/css" href="temas/clientside/geral.css" rel="stylesheet" media="screen" />
<!--[if IE]><link type="text/css" href="temas/clientside/IEstuff.css" rel="stylesheet" media="screen" /><![endif]-->

</head>

<body>

    <div id="container">

  <div id="header">
    <h1>AroundField</h1>
    <p>Sharing Portugal with the World</p>
  </div>

  <div class="content">
    <h2>Na Aroundfield acreditamos que o bom trabalho gera bons negócios. Este é o nosso compromisso. </h2>
    <h3>Ligar produtores e compradores numa base global, criando uma rede comercial que integra fornecimentos, marketing e transporte.</h3>
    <h3>Acompanhar todos os processos, sejam eles operacionais, logísticos ou aduaneiros, para que o seu produto chegue aos novos parceiros, nas melhores condições.</h3>
    <h4>Como?</h4>
    <p>Avaliação e preparação</p>
    <ul>
      <li>Avaliação da capacidade da empresa, e dos produtos oferecidos à exportação.</li>
      <li>Pesquisa de mercado.</li>
      <li>Auxílio na preparação do(s) produto(s) da empresa nacional para o mercado externo.</li>
      <li>Assessoria na adequação de embalagens, rótulos em língua estrangeira, etc.</li>
      <li>Auxílio na formação de preços para exportação.</li>
    </ul>
    <p>Promoção</p>
    <ul>
      <li>Selecção de possíveis países compradores.</li>
      <li>Apoio à elaboração de materiais promocionais, tais como site de Internet, panfletos explicativos, catálogos, etc.</li>
      <li>Captação de clientes no mercado externo.</li>
      <li>Envio de amostras para promoção do produto, consignação, participação em feiras e congressos.</li>
      <li>Suporte na negociação internacional.</li>
    </ul>
    <p>Execução</p>
    <ul>
      <li>Colaboração na estratégia de exportação, vendas e distribuição internacional.</li>
      <li>Preparação e organização de feiras, certames e mostras de produtos e serviços.</li>
      <li>Disponibilização de ferramenta e-commerce, para trocas comerciais online.</li>
      <li>Acompanhamento até ao destino final.</li>
    </ul>
  </div>

  <div id="footer">
    <div>
      <p class="company">AroundField Portuguese Trading Company Lda</p>
      <p class="address">
        Praceta Fernando Vale, 2A <br />
        1750-461 LISBOA, Portugal
      </p>
      <p class="contacts">
        Tel.:(+351) 210 992 871 <br />
        E.: info@aroundfield.pt
      </p>
      <p class="copyright">© <?php echo date("Y"); ?> AroundField. Todos os direitos reservados. Design by <a href="http://www.ideal-line.pt">Ideal Line</a>.</p>
    </div>
    <p class="villaPT"><a>Villa Portucalle - Traditional Food & Arts Trading Company</a></p>
  </div>

  <div id="form">
    <?=$_SESSION['success'];?>
    <h4>Deseja ser contactado(a)?</h4>
    <form action="mess.php" method="post">
      <p><label for="nome">Nome</label> <input type="text" name="nome" id="nome" value="<?=$_SESSION['nome']?>"/></p>
      <p><label for="email">Email <span class="error">*</span></label> <input type="text" name="email" id="email" value="<?=$_SESSION['email']?>"/></p>
      <p><textarea name="conteudo" id="conteudo"><?=$_SESSION['conteudo']?></textarea></p>
      <p><input type="submit" name="enviar" value="enviar »" /></p>
      <input type='hidden' value='1' name='submitted' />
    </form>
  </div>

</div>

</body>
</html>

mess.php

<?php
session_start();
function is_email($email) {
		eregi("^([0-9a-zA-Z]+)([.,_]([0-9a-zA-Z]+))*[@]([0-9a-zA-Z]+)([.-]([0-9a-zA-Z]+))*[.]([0-9a-zA-Z]){2}([0-9a-zA-Z])?$",$email,$match);
		list($email_comp ,$login, $domain, $sufixies) = $match;
		if ($email_comp == $email) {
			return true;
		} else {
			return false;
		}
	}

	// Prepare email to send
	if ($_POST['submitted']) {

		$para = "nuno.baixinho@epochmultimedia.com";  //info@aroundfield.pt
		$assunto = "contacto via website\r\n";
		$conteudo = $_POST['conteudo']."\r\n";
		$conteudo .= $_POST['nome']."\r\n";
		$conteudo .= $_POST['email']."\r\n";
		$header='MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n" . 'From: Website <no-reply@localhost>' . "\r\n";

		$_SESSION['nome'] = "";
		$_SESSION['email'] = "";
		$_SESSION['conteudo'] = "";
		$_SESSION['nome'] = $_POST['nome'];
		$_SESSION['email'] = $_POST['email'];
		$_SESSION['conteudo'] = $_POST['conteudo'];
		
				// Validate email and required fields
		
		if(!is_email($_POST['email']) || $_POST['email'] == "") {

			$erro2 = 1;
			$_SESSION['email'] = "";
			$sucesso= "<p class='alert error'><strong>(!)</strong> Introduza um email válido..</p>";
			$_SESSION['success']=$sucesso;
			header('Location: index.php');
						
		}
		if ($erro1 != 1 && $erro2 != 1) {

			if (mail($para, $assunto, $conteudo, $header)) {			   
			   $sucesso = "<p class='alert confirm'>Mensagem enviada!</p>";
			   $_SESSION['success']=$sucesso;
			   header('Location: index.php');
			   
			 
			  $_SESSION['nome'] = "";
			  $_SESSION['email'] = "";
			  $_SESSION['conteudo'] = "";
			  
			} else {
			    $sucesso = "<p class='alert error'><strong>(!)</strong> Ocorreram erros..</p>";
				$_SESSION['success']=$sucesso;
				header('Location: index.php');
				
				
				
			
		    }
		}		
	}
	

	
	?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>AroundField | Sharing Portugal with the World</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="pt">
<meta name="author" content="www.epochmultimedia.com - geral@epochmultimedia.com">
<meta name="copyright" content="2011 &copy; A. Morgado Gama">
<meta name="description" content="A. Morgado Gama - Página temporária">
<meta name="keywords" content="reabilitar, edifícios, construção, civil">

<link type="text/css" href="temas/clientside/geral.css" rel="stylesheet" media="screen" />
<!--[if IE]><link type="text/css" href="temas/clientside/IEstuff.css" rel="stylesheet" media="screen" /><![endif]-->

</head>

<body>

</body>
</html>

Ok. I got it working.

This is what i have now.

index.php

<?
session_start();
?>

Content...)

<?=$_SESSION['success'];?>
    <h4>Deseja ser contactado(a)?</h4>
    <form action="mess.php" method="post">
      <p><label for="nome">Nome</label> <input type="text" name="nome" id="nome" value="<?=$_SESSION['nome']?>"/></p>
      <p><label for="email">Email <span class="error">*</span></label> <input type="text" name="email" id="email" value="<?=$_SESSION['email']?>"/></p>
      <p><textarea name="conteudo" id="conteudo"><?=$_SESSION['conteudo']?></textarea></p>
      <p><input type="submit" name="enviar" value="enviar »" /></p>
      <input type='hidden' value='1' name='submitted' />
    </form>
  </div>

</div>

</body>
</html>
<?
session_destroy();
?>

mess.php:

<?php
session_start();

function is_email($email) {
		eregi("^([0-9a-zA-Z]+)([.,_]([0-9a-zA-Z]+))*[@]([0-9a-zA-Z]+)([.-]([0-9a-zA-Z]+))*[.]([0-9a-zA-Z]){2}([0-9a-zA-Z])?$",$email,$match);
		list($email_comp ,$login, $domain, $sufixies) = $match;
		if ($email_comp == $email) {
			return true;
		} else {
			return false;
		}
	}

	// Prepare email to send
	if ($_POST['submitted']) {
		$para = "mail@mail.com";
		$assunto = "contacto via website\r\n";
		$conteudo = $_POST['conteudo']."\r\n";
		$conteudo .= $_POST['nome']."\r\n";
		$conteudo .= $_POST['email']."\r\n";
		$header='MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n" . 'From: Website <no-reply@localhost>' . "\r\n";

		$_SESSION['nome'] = "";
		$_SESSION['email'] = "";
		$_SESSION['conteudo'] = "";
		$_SESSION['nome'] = $_POST['nome'];
		$_SESSION['email'] = $_POST['email'];
		$_SESSION['conteudo'] = $_POST['conteudo'];
		
		
				// Validate email and required fields
		
		if(!is_email($_POST['email']) || $_POST['email'] == "") {
			$erro2 = 1;
			$_SESSION['email'] = "";
			$sucesso= "<p class='alert error'><strong>(!)</strong> Introduza um email válido..</p>";
		}
		if ($erro1 != 1 && $erro2 != 1) {
			if (mail($para, $assunto, $conteudo, $header)) {			   
			  $_SESSION['nome'] = "";
			  $_SESSION['email'] = "";
			  $_SESSION['conteudo'] = "";
			  $sucesso = "<p class='alert confirm'>Mensagem enviada!</p>";
			} else {
			    $sucesso = "<p class='alert error'><strong>(!)</strong> Ocorreram erros..</p>";
											
		    }
		}
		$_SESSION['success']=$sucesso;			  
	    header('Location: index.php');	
	}
	?>

Thanks for the help guys!! And if anyone wants to use this, please be free to do so.

:D nice one phpbeginners. I also forgot to add that line when I first tried the php mailer.

-----------------------------------
<SPAM>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.