Contact form in php does not send

Asked

Viewed 298 times

1

<?php

    $name     =   $_POST['name']; //pega os dados que foi digitado no ID name.
    $email    =   $_POST['email']; //pega os dados que foi digitado no ID email.
    $assunto  =   $_POST['assunto']; //pega os dados que foi digitado no ID Assunto.
    $mensagem  =   $_POST['mensagem']; //pega os dados que foi digitado no ID Mensagem.

    $headers = "MIME-Version: 1.0" . "\r\n"; 
    $headers .= "Content-type: text/html; charset=utf-8" . "\r\n"; 
    $headers .= "From: Site <comercial@meu_site.art.br>" . "\r\n";
    $headers .= "Reply-To: comercial@meu_site.art.br" . "\r\n";
    $headers .= "X-Mailer: PHP/" . phpversion();


/*abaixo contém os dados que serão enviados para o email
cadastrado para receber o formulário*/

       $corpo = "Formulario Enviado\n";
       $corpo .= "Nome: " . $name . "\n";
       $corpo .= "E-mail: " . $email . "\n";
       $corpo .= "Assunto: " . $assunto . "\n";
       $corpo .= "Mensagem: " . $mensagem . "\n";


       $email_to = 'comercial@meu_site.art.br'; //não esqueça de substituir este email pelo seu.

    $status = mail($email_to, $email, $corpo, $headers); //enviando o email.

    if($status) {
        echo "<script> alert('Mensagem enviada com sucesso!'); </script>"; //mensagem de form enviado com sucesso.
    }
    else {
        echo "<script alert('Falha ao enviar Mensagem.'); </script>"; //mensagem de erro no envio.
    }
    echo "<script> window.location.href = 'index.html'; </script>"; //mudar o site para redirecionar após o envio do form.
?>

Can anyone tell me ok it’s wrong?

  • What error returns? You already know Phpmailer?

  • gave the information that was sent successfully, but the email with the information does not arrive. I do not know yet, so far I only did the introduction in PHP, I will start to get into this subject next semester

  • I believe that PHPMailer is not in the grid of any course, I suggest you use it, take a look: http://phpmailer.worxware.com/index.php

  • If you are testing on localhost you will not send the email even unless Voce has made the necessary settings for it. What function mail() returns whether it was executed without errors, and not whether the email was sent.

  • So there’s no way I can fix this php file to continue using it?

  • I couldn’t access the address http://meu_site.art.br/. Does it exist? Has an email server set up for it?

  • No Hugo this is just to mark the place of my site. I managed to fix PHP but there is only one problem yet. Is that I can not set the sender

Show 2 more comments

1 answer

0

Try using if directly in the mail function to see if it returns an error.

       if (mail($email_to, $email, $corpo, $headers)){
            echo "<script> alert('Mensagem enviada com sucesso!'); </script>"; 
        }
        else {
            echo "<script alert('Falha ao enviar Mensagem.'); </script>"; 
        }
        echo "<script> window.location.href = 'index.html'; </script>"; 
  • Thanks Alvaro, but I’ve already arranged the receipt of the information, I’m just having trouble defining the sender. You know how to do

Browser other questions tagged

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