Advertisement
info1atual

Formulário de Contato (PHP)

Sep 15th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <h2>Contato</h2>
  2.  
  3. <?php
  4. // Checagem se é um submit na página
  5. if
  6. (!isset($_POST["submit"])) {
  7. ?>
  8.  
  9. <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
  10.  
  11. De: <br>
  12. <input type="text" name="email">
  13. <br>
  14. Assunto: <br>
  15. <input type="text" name="assunto">
  16. <br>
  17. Mensagem: <br>
  18. <textarea rows="10" cols="40" name="mensagem"></textarea>
  19. <br>
  20. <input type="submit" name="submit" value="OK">
  21.  
  22. </form>
  23.  
  24. <?php
  25. } else {
  26.   // Se o usuário submeter o formulário
  27.   // Checa se o campo "email" está setado
  28.   if (isset($_POST["email"])) {
  29.     $from = $_POST["email"];
  30.     $subject = $_POST["assunto"];
  31.     $message = $_POST["mensagem"];
  32.     // Mensagem se exceder 70 linhas (PHP rule)
  33.     $message = wordwrap($message, 70);
  34.     // Envio do email
  35.     mail("contato@site.com",$subject,$message,"From: $from\n");
  36.     echo "Obrigado pelo contato!";
  37.   }
  38. }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement