← Desenvolvimento

Ajuda formulário php

Lida 2826 vezes

Offline

pmlc 
Membro
Mensagens 469 Gostos 0
Feedback +2

Troféus totais: 25
Trófeus: (Ver todos)
Level 5 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 4 Level 3 Level 2 Level 1

Boa noite,
Quero uma ajuda vossa. Ao configurar um formulario em php, a mensagem é enviada correctamente mas ao receber os campos aparecem em branco, nao contendo qualquer informação.

Código: [Seleccione]
<font face="verdana" size="1">
<form method="post" action="contact.php">
nome:<br>
<input type="text" name="nome" style="border: 1px solid #cccccc; background-color: #ffffff;" size="26" value="nome"><br><br>
email:<br>
<input type="text" name="email" style="border: 1px solid #cccccc; background-color: #ffffff;" size="26" value="email"><br><br>
telemovel:<br>
<input type="text" name="telemovel" style="border: 1px solid #cccccc; background-color: #ffffff;" size="26" value="telemovel"><br><br>
mensagem:<br>
<textarea name="mensagem" cols="40" rows="3" style="border: 1px solid #cccccc; background-color: #ffffff;"></textarea><br><br>
<input type="submit" value="send" style="border: 1px solid #cccccc; background-color: #ffffff;">
</p>
</form>
</font>


ficheiro contact.php

Código: [Seleccione]
<?php
if &#40;$_POST['nome'&#93; != "" && $_POST['email'&#93; && $_POST['mensagem'&#93; &#41; &#123;
$subject="PLINO";
$ip=$_SERVER["REMOTE_ADDR"&#93;;
$host $ip;
$mon=date&#40;m&#41;;
$day=date&#40;j&#41;;
$year=date&#40;y&#41;;
$hour=date&#40;g&#41;;
$min=date&#40;i&#41;;
$sec=date&#40;s&#41;;
$hour=$hour-2;
if&
#40;$hour<=0&#41; &#123; $hour+=12; &#125;
$ts "$hour&#58;$min&#58;$sec on $day/$mon/$year";


$to="comercial@plino.com";

$body="

nome = 
$nome

email = 
$email

telemovel = 
$telemovel

mensagem = 
$mensagem


Host&#58; 
$host
Time&#58; 
$ts";

$email "From&#58; Form <$to>";
mail&#40;$to, $subject, $body, $email&#41;;
?>


<html>
<head>
<title>Email Sent</title>
</head>
<body bgcolor="#ffffff" text="#666666">

<p>&nbsp;</p>
<center>
<table border="1" cellpadding="3" cellspacing="0" width="400" bordercolor="#919191" bgcolor="#E6E6E6">
  <tr>
    <td width="100%">
      <p><center><b><font color="#000000">Email was successfully sent to: <?php echo $to ?></font></b></center>
     
    </td>
  </tr>
</table>

</body>
</html>

<?php
&#125; else &#123;
?>


<html>
<head>
<title>Contact email error</title>
</head>

<body bgcolor="#ffffff" text="#666666">
<p><center>
<table border="1" cellpadding="3" cellspacing="0" width="400" bordercolor="#919191" bgcolor="#E6E6E6">
  <tr>
    <td width="100%">
<center>
<b>There was an error with processing the email.</b><br>
<p>
<font color="#FF0000">Errors where:</font><br>
<?php
If &#40;!$_POST['nome'&#93;&#41;
echo "nome field is empty<br>";

If &#40;!$_POST['email'&#93;&#41;
echo "email field is empty<br>";

If &#40;!$_POST['mensagem'&#93;&#41;
echo "mensagem field is empty<br>";

?>

<p>
Email message wasn't sent
     
    </td>
  </tr>
</table>
</body>
</html>

<?php
&#125;
?>




Agradeço desde já a vossa atenção.
Offline

=IceBurn= 
Membro
Mensagens 897 Gostos 3
Feedback +3

Troféus totais: 32
Trófeus: (Ver todos)
Windows User Level 6 Linux User Mobile User Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5

Register Globals OFF (e muito bem)
 então
Código: [Seleccione]
$body="

nome = ".$_POST['nome']."

email = ".$_POST['email']."  

telemovel = ".$_POST['telemovel']."  

mensagem = ".$_POST['mensagem']."


Host: $host
Time: $ts";
Offline

pmlc 
Membro
Mensagens 469 Gostos 0
Feedback +2

Troféus totais: 25
Trófeus: (Ver todos)
Level 5 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 4 Level 3 Level 2 Level 1

Obrigado,
situação resolvida. Obrigado mais uma vez pela tua ajuda!
Offline

XUTOS-83 
Membro
Mensagens 23 Gostos 0
Troféus totais: 24
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 5 Level 4 Level 3 Level 2 Level 1 10 Posts First Post

Bem aproveito este tópico pois tb tenho uma duvida num formulário q estou a usar, no fim após o formulário ser preenchido ele faz:

    );
echo "<p align=center>A sua mensagem foi enviada com sucesso.</p>";
echo "<p align=center>Para voltar a minha pagina use o botao back</p>";
?>

Seria possível em vez de aparecer uma pagina em branco com estas mensagens em direccionar o user para uma pagina especifica?

Desde já obg.
 :wink:
Offline

=IceBurn= 
Membro
Mensagens 897 Gostos 3
Feedback +3

Troféus totais: 32
Trófeus: (Ver todos)
Windows User Level 6 Linux User Mobile User Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5

Podes utilizar
Código: [Seleccione]
header("location: nome_da_pagina.php"); Mas isto dito assim é muito vago, pois se não for inserido no sítio certo vai dar-te erro, de modo que se postasses o código seria mais fácila ajudar-te.
Offline

XUTOS-83 
Membro
Mensagens 23 Gostos 0
Troféus totais: 24
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 5 Level 4 Level 3 Level 2 Level 1 10 Posts First Post

OK, o código q estou a usar e este:
Código: [Seleccione]

<?
$nome      = $_POST["nome"];
$site     = $_POST["site"];
$email   = $_POST["email"];
$fone  = $_POST["fone"];
$assunto   = $_POST["assunto"];
$mensagem  = $_POST["mensagem"];

global $email;

$data      = date("d/m/y");
$ip        = $_SERVER['REMOTE_ADDR'];
$navegador = $_SERVER['HTTP_USER_AGENT'];
$hora      = date("H:i");

mail ("*****@*********.com",
      "$assunto",
      "Nome: $nome\nData: $data\nIp: $ip\nNavegador: $navegador\nHora: $hora\nSite: $site\nE-mail: $email\nTelefone: $fone\n\nMensagem: $mensagem",
      "From: $email"
     );

$site   = "*****@*********.com";
$titulo = "RE:Contacto";
$msg    = "$nome, desde já agradeço o seu contacto, prometo uma resposta o mais breve possível.\n*****";

mail("$email",
     "$titulo",
     "$msg",
     "From: $site"
    );
echo "<p align=center>$nome, a sua mensagem foi enviada com sucesso. Responderei em breve.</p>";
echo "<p align=center>Para voltar a minha pagina use o botao back/recuar do seu navegador.</p>";
?>
Offline

=IceBurn= 
Membro
Mensagens 897 Gostos 3
Feedback +3

Troféus totais: 32
Trófeus: (Ver todos)
Windows User Level 6 Linux User Mobile User Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5

Bem, se é só mesmo isso então não é preciso grandes alterações...
Código: [Seleccione]
<?php
$nome  
$_POST["nome"&#93;; 
$site  $_POST["site"&#93;; 
$email $_POST["email"&#93;; 
$fone  $_POST["fone"&#93;; 
$assunto  $_POST["assunto"&#93;; 
$mensagem $_POST["mensagem"&#93;; 

global $email

$data      date&#40;"d/m/y"&#41;; 
$ip        $_SERVER['REMOTE_ADDR'&#93;; 
$navegador $_SERVER['HTTP_USER_AGENT'&#93;; 
$hora      date&#40;"H&#58;i"&#41;; 

@mail &#40;"*****@*********.com", 
      
"$assunto"
      
"Nome&#58; $nome\nData&#58; $data\nIp&#58; $ip\nNavegador&#58; $navegador\nHora&#58; $hora\nSite&#58; $site\nE-mail&#58; $email\nTelefone&#58; $fone\n\nMensagem&#58; $mensagem"
      
"From&#58; $email
     
&#41;; 

$site   "*****@*********.com"
$titulo "RE&#58;Contacto"
$msg    "$nome, desde já agradeço o seu contacto, prometo uma resposta o mais breve possível.\n*****"

@
mail&#40;"$email", 
     
"$titulo"
     
"$msg"
     
"From&#58; $site
    
&#41;; 

header&#40;"Location&#58; http&#58;//site.com"&#41;;
?>
Offline

XUTOS-83 
Membro
Mensagens 23 Gostos 0
Troféus totais: 24
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 5 Level 4 Level 3 Level 2 Level 1 10 Posts First Post

=IceBurn=

Mt obrigado, funciona perfeitamente. ;)