0

I made a contact form using php, when i press the submit button appears: Not Found The requested document was not found on this server.

I believe the error is related with $PHP_SELF, because the text ''?%20$PHP_SELF;%20?'' appears in the address bar of the browser after the website url. ps: i change the emails and the urls to post here, and ignore the portuguese instructions. here's the php:

<?php

if (isset($_POST['BTEnvia'])) {
 
 //Variaveis de POST, Alterar somente se necessário 
 //====================================================
 $nome = $_POST['nome'];
 $email = $_POST['email'];
 $telefone = $_POST['telefone']; 
 $mensagem = $_POST['mensagem'];
 //====================================================
 
 //REMETENTE --> ESTE EMAIL TEM QUE SER VALIDO DO DOMINIO
 //==================================================== 
 $email_remetente = "email@example"; // deve ser uma conta de email do seu dominio 
 //====================================================
 
 //Configurações do email, ajustar conforme necessidade
 //==================================================== 
 $email_destinatario = "email@example"; // pode ser qualquer email que receberá as mensagens
 $email_reply = "$email"; 
 $email_assunto = "Contact"; // Este será o assunto da mensagem
 //====================================================
 
 //Monta o Corpo da Mensagem
 //====================================================
 $email_conteudo = "Nome = $nome \n"; 
 $email_conteudo .= "Email = $email \n";
 $email_conteudo .= "Telefone = $telefone \n"; 
 $email_conteudo .= "Mensagem = $mensagem \n"; 
 //====================================================
 
 //Seta os Headers (Alterar somente caso necessario) 
 //==================================================== 
 $email_headers = implode ( "\n",array ( "From: $email_remetente", "Reply-To: $email_reply", "Return-Path: $email_remetente","MIME-Version: 1.0","X-Priority: 3","Content-Type: text/html; charset=UTF-8" ) );
 //====================================================
 
 //Enviando o email 
 //==================================================== 
 if (mail ($email_destinatario, $email_assunto, nl2br($email_conteudo), $email_headers)){ 
     echo "</b>E-Mail enviado com sucesso!</b>"; 
     } 
   else{ 
     echo "</b>Falha no envio do E-Mail!</b>"; } 
 //====================================================
} 
?>
<td width="25%"><p align="center"><img src="example.jpg" width="430" height="131" alt=""/>
  <form action="<? $PHP_SELF; ?>" method="POST"> 
 
  
 <table width="423" border="0" align="center">
   <tbody>
     <tr>
       <td width="417"><h1 align="center">
          <p style="font-size: 36px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', 'DejaVu Sans', Verdana, sans-serif; font-style: normal;">Solicite seu Orçamento!</p></td>
        </tr>
     <tr>
       <td><p><span style="font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, sans-serif">Nome:</span><br />
         <input name="nome" type="text" required="required" size="30">
         </p>
            <p> <span style="font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, sans-serif">E-mail:</span><br />
              <input name="email" type="text" required="required" size="30">
            </p>
            <p> <span style="font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, sans-serif">Telefone (00 00000 0000):</span><br />
              <input name="telefone" type="text" required="required" autocomplete="off" size="35">
            </p>
            <p> <span style="font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, sans-serif">Mensagem:</span><br />
              <textarea name="mensagem" cols="50" rows="10" required="required" type="text" size="35"></textarea>
            </p>
            <p>
              <input type="submit" name="BTEnvia" value="Enviar">
              <input type="reset" name="BTApaga" value="Apagar">
          </p></td>
        </tr>
      </tbody>
  </table>
<p>&nbsp;</p> 

1 Answers1

-1

It's most likely that you don't have short_open_tags turned on. This means that the value of action is written just as plain text.

You can easily change this to: action="<?php echo $PHP_SELF ?>"

Additionally, PHP_SELF, is usually inside of the $_SERVER variable, unless you have it defined already. (eg: $_SERVER['PHP_SELF'] not $PHP_SELF).

Whole code: action="<?php echo $_SERVER['PHP_SELF']?>"

Lastly, as mentioned in the comments, its not recommended to use PHP_SELF because of security vulnerabilities. See more here: PHP_SELF and XSS

Samuel Cook
  • 16,620
  • 7
  • 50
  • 62