Error sending email through the mail function

Asked

Viewed 35 times

0

I need to make one form that send a message to a mail. I already used "mailto:...." but when I went to test I was always opening the outlook.

So he went to research and I ended up with this code on PHP.

<?php 

if(!isset($_POST['submit']))
{
    echo "erro!";
}

$nome = $_POST['nome'];
$mail = $_POST['email'];
$telefone = $_POST['telefone'];
$mensagem = $_POST['mensagem'];

if(empty($nome)||empty($mail)){
    echo "Nome e mail obrigatórios";
    exit;
}

$mail2 = "[email protected]";
$assunto = "Saber Infinito";
$corpo = "Recebeu uma mensagem de $nome.\n E-mail: $mail.\n 
Telefone: $telefone.\n Mensagem:\n $mensagem";

$para = "bbgibellino@gmail";
$header = "E-mail de $nome";

$result = mail($para,$assunto,$corpo,$header);

if(!$result) {   
     echo "<script>
        document.location.href = '../index.html';   
        alert('Erro! Mensagem não enviada!');    
     </script>"; 
} else {
    echo "<script>
        document.location.href = '../index.html';   
        alert('Obrigado! Mensagem enviada');
     </script>";
}

?>

PS: Sorry to send through a website but I could not incorporate in the question

  • Bruno although the question is not duplicate, the answer is the right one for your question. If you find that the answers to this question do not help you here tell us why.

  • @Jorgeb. But I don’t want to send attachments and this question is focused on that point. I don’t know if you saw the attachment I sent, but what’s on the link you posted I already have, the problem is it doesn’t work. And I’d like to know why.

  • So you have to put in the code that you have and how you’re using it to get an idea of what the problem is.

  • And the PHP log when trying to send mail.

  • Makes var_dump($result); and comments on if - Else code...

  • I advise you to use Phpmailer, as it has several features, mainly send authenticated emails. See the tutorial of colleague Thiago Belem. http://blog.thiagobelem.net/enviar-e-mails-pelo-php-usando-o-phpmailer/

Show 1 more comment
No answers

Browser other questions tagged

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