Form does not send the information to the email

0

I need the information in my form to be sent to my email I'm doing in php but it does not work follow my code:

        <form action="email.php" method="post">
    <label for="Nome">nome:</label>
    <input type="text" name="Nome" size="35" /><br>

    <label for="Email">E-mail:</label>
    <input type="text" name="Email" size="35" /><br>

    <label for="Fone">Telefone:</label>
    <input type="text" name="Fone" size="35" /><br>

    <label for="Mensagem">Mensagem:</label>
    <textarea name="Mensagem" rows="8" cols="40"></textarea><br> 

    <input type="submit" name="Enviar" value="Enviar" />
</form>

My code in php is in a separate file from my code:

    <?php
$Nome       = $_POST["Nome"];   // Pega o valor do campo Nome
$Fone       = $_POST["Fone"];   // Pega o valor do campo Telefone
$Email      = $_POST["Email"];  // Pega o valor do campo Email
$Mensagem   = $_POST["Mensagem"];   // Pega os valores do campo Mensagem

// Variável que junta os valores acima e monta o corpo do email

$Vai        = "Nome: $Nome\n\nE-mail: $Email\n\nTelefone: $Fone\n\nMensagem: $Mensagem\n";

require_once("phpmailer/class.phpmailer.php");

define('GUSER', '[email protected]');   // <-- Insira aqui o seu GMail
define('GPWD', 'lalala123');        // <-- Insira aqui a senha do seu GMail

function smtpmailer($para, $de, $de_nome, $assunto, $corpo) { 
    global $error;
    $mail = new PHPMailer();
    $mail->IsSMTP();        // Ativar SMTP
    $mail->SMTPDebug = 2;       // Debugar: 1 = erros e mensagens, 2 = mensagens apenas
    $mail->SMTPAuth = true;     // Autenticação ativada
    $mail->SMTPSecure = 'ssl';  // SSL REQUERIDO pelo GMail
    $mail->Host = 'smtp.gmail.com'; // SMTP utilizado
    $mail->Port = 587;          // A porta 587 deverá estar aberta em seu servidor
    $mail->Username = GUSER;
    $mail->Password = GPWD;
    $mail->SetFrom($de, $de_nome);
    $mail->Subject = $assunto;
    $mail->Body = $corpo;
    $mail->AddAddress($para);
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo; 
        return false;
    } else {
        $error = 'Mensagem enviada!';
        return true;
    }
}

// Insira abaixo o email que irá receber a mensagem, o email que irá enviar (o mesmo da variável GUSER), 

 if (smtpmailer('[email protected]', '[email protected]', 'felipe', 'Assunto do Email', $Vai)) {

    Header("location:http://www.dominio.com.br/obrigado.html"); // Redireciona para uma página de obrigado.

}
if (!empty($error)) echo $error;
?>

I run the project and gave this error:

    
asked by anonymous 27.05.2015 / 19:07

2 answers

2
  $headers .= "From:  dominio.com.br<[email protected]>\n";
  $headers .= "X-Sender:  <[email protected]>\n";
  $headers .= "X-Mailer: PHP  v".phpversion()."\n";
  $headers .= "X-IP:  ".$_SERVER['REMOTE_ADDR']."\n";
  $headers .= "Return-Path:  <[email protected]>\n";
  $headers .= "MIME-Version: 1.0\n";

You need to configure this snippet with information from your server or from a third-party server, so it is not working.

Since you're learning, this article / a> can help you with the configuration of sending emails via SMTP through Gmail that is free.

    
27.05.2015 / 20:03
1

PHP code needs to be compiled, and for this you need a web server (HTTP) and PHP to run the code!

Install WAMP or XAMPP or EasyPHP

WAMP

XAMPP

EasyPHP

These WAMP packages (Windows, Apache, MySQL, PHP) (or LAMP - where L is Linux) are programs that install the Web server (Apache), PHP and a database (MySQL) and then you can test your PHP code on your machine.

As soon as you install and start Apache (web server), you will put the files in a pre-determined folder (depends on where you installed the server) and there you can access by link and take the tests!

Sending Email via SMTP

To send the emails, you will need a SMTP server, however I do not recommend that you try to install one on your machine, because besides headache, if it is not very well configured, someone over the internet may end up sending SPAM on your computer to anywhere in the world.

If you'd like to try sending emails, I recommend that you install Papercut . It is a small SMTP server that sends any email to itself. So you can test and view the email directly through it. Just download it and install, then just try to send the email again through PHP and you will see that Papercut has received a new message!

    
27.05.2015 / 20:10