Form does not send to e-mail (PHP)

Asked

Viewed 224 times

1

I have two pages created, index.php and processForm.php. The first one counts with the form and the second one takes charge of taking the data and sending it to my e-mail. But despite putting both files on the server (000webhost) and sending, my email (gmail) does not receive anything. I’m a beginner so I need all the help I can get :D

index php.

<?php

$msg = 0;
@$msg = $_REQUEST['msg'];

?>

<html>

<head>
    <meta charset="utf-8">
    <title></title>
</head>

<body>

    <?php
        if ($msg=="enviado"):
    ?>
    <h1>Mensagem enviada</h1>

    <?php else: ?>

    <fieldset>
        <legend><h3>Formulário de contato</h3></legend>
        <form action="processaForm.php" method="post">
            <label for="name">Nome:</label><br>
            <input id="nome" type="text" name="nome" required><br>
            <label for="telefone">Telefone:</label><br>
            <input id="telefone" type="tel" name="telefone" requerid><br>
            <label for="email">Email:</label><br>
            <input id="email" type="email" name="email" requerid><br>
            <label for="assunto">Assunto:</label><br>
            <textarea id="assunto" name="assunto"> </textarea><br>
            <input type="submit" name="enviar">
        </form>
    </fieldset>

    <?php endif; ?>

</body>

php processForm.

<?php

$para = "[email protected]";
$assunto = "Consulta agendada";
$nome = $_REQUEST['nome'];
$fone = $_REQUEST['telefone'];
$email = $_REQUEST['email'];
$msg = $_REQUEST['assunto'];

    $corpo = "<strong> Mensagem de contato </strong><br><br>"; 
    $corpo .= "<br><strong> Nome: </strong> $nome"; 
    $corpo .= "<br><strong> Telefone: </strong> $fone";
    $corpo .= "<br><strong> Email: </strong> $email";
    $corpo .= "<br><strong> Mensagem: </strong> $msg";   

    $header = "From: $email Reply-to: $email";
    $header .= "Content-type: text/html; charset = utf-8";

@mail($para, $assunto, $corpo, $header);

header("location:index.php?msg=enviado");
?>
  • Takes the @ of everything and runs to see. Also see if Voce has configured the php.ini, there checks the SMTP credentials

  • That part: "Also see if Voce set up php.ini, there checks the credentials of SMTP" I didn’t understand anything, sorry. I’m pretty beginner even rsrs

  • Okay, but Voce took the @ and executed the code to see if an error appears ?

  • I removed, I upended the files on the server and still didn’t send.

  • Bro, I use xampp, by local server has no way to test sending email. Or have and I’m reading?

  • But you have to configure it, I recommend you use it then: https://github.com/PHPMailer/PHPMailer there is the documentation of how to use it

  • see on the internet tutorials how to use Phpmailer, on youtube Voce thinks varios. It is not very recommended to use only the function mail() native to PHP

  • I understand, I’ll study about.

Show 3 more comments
No answers

Browser other questions tagged

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