Blank email with PHP

Asked

Viewed 97 times

0

I made a short form to test the mail function, the email is being sent but arrives with the name and message fields blank. I saw other forums and they indicate other libraries but wanted to know what I’m missing.

<form action="enviar.php" method="post">

    <label for="nome">Nome:</label>
    <input type="text" name="nome" required><br><br>

    <label for="email">Email:</label>
    <input type="email" name="email" required><br><br>

    <label for="mensagem">Mensagem:</label>
    <textarea name="mensagem"></textarea><br><br>

    <input type="submit" name="enviar" value="Enviar">

</form><!-- FORM -->

PHP

<?php

$nome = $_POST['nome'];
$email = $_POST['email'];
$mensagem = $_POST['mensagem'];
$titulo = 'Email Curso PHP';
$dest = '[email protected]';
$dados = 'Nome :'.$nome." Email: ".$email." Destinatário: ".$dest." Mensagem: ".$mensagem;

mail($dest, $titulo, $dados);


?>
  • 1

    Checked if the values are correctly arriving in $_POST?

  • Yes, but I managed to make it work by putting everything get. It’s correct this way?

1 answer

-4

<?php

$nome = $_REQUEST['nome'];
$email = $_REQUEST['email'];
$mensagem = $_REQUEST['mensagem'];
$titulo = 'Email Curso PHP';
$dest = '[email protected]';
$dados = 'Nome :'.$nome." Email: ".$email." Destinatário: ".$dest." Mensagem: ".$mensagem;

mail($dest, $titulo, $dados);

if you are in a Linux environment check if you have read/write permission

  • Your answer looks exactly the same as the author of the question. Try not to post only code, explain how to solve the problem.

  • solves the problem by changing the $_POST pro $_REQUEST,

Browser other questions tagged

You are not signed in. Login or sign up in order to post.