I made this code to send an automatic email to the db user. The registration is ok, but the email does not go to the client. What's wrong?

0

php code

<?php

include "conectar.php";


//comando para iserir dados direto do formulário para o banco de dados

$vnome=$_POST['nome'];
$vcpf=$_POST['cpf'];
$videntidade=$_POST["identidade"];
$vtelefone=$_POST["telefone"];
$vcelular=$_POST["celular"];
$vemail=$_POST["email"];
$vcep=$_POST["cep"];
$vendereco=$_POST["endereco"];
$vcomplemento=$_POST["complemento"];
$vbairro=$_POST["bairro"];
$vcidade=$_POST["cidade"];
$vuf=$_POST["uf"];
$vsexo=$_POST["sexo"];
$vidade=$_POST["idade"];
$vpeso=$_POST["peso"];


$sql="INSERT INTO solidario VALUES (NULL, '$vnome', '$vcpf', '$videntidade', '$vtelefone', '$vcelular', '$vemail', '$vcep', '$vendereco', '$vcomplemento', '$vbairro', '$vcidade', '$vuf', '$vsexo', '$vidade', '$vpeso')";

$res=mysqli_query($con,$sql);
$num=mysqli_affected_rows($con);

if($num == 1){

mail('[email protected]',$vnome,$vcpf, 'FROM:$vemail');
echo"<META HTTP-EQUIV=REFRESH CONTENT = '0;URL=index.php'>
                <script type=\"text/javascript\">
                    alert(\"Seu cadastrado foi realizado com sucesso!.\");
                </script>

            ";  

}else{
    echo"   <META HTTP-EQUIV=REFRESH CONTENT = '0;URL=index.php'>
                <script type=\"text/javascript\">
                    alert(\"seu CPF já foi cadastrado!.\");
                </script>                   
            ";
}

mysqli_close($con);
?>
    
asked by anonymous 20.10.2017 / 05:55

1 answer

1

I think it's because of 'FROM:$vemail' , When you use ' PHP does not interpret anything inside it .

Change to:

'FROM: '.$vemail

or

"FROM: $vemail"

Should work. However, there is another detail, you are defining FROM, not TO. That is, $vemail is that you are "sending" the message and not receiving, I believe you should do something like:

mail($vemail, $vnome, $vcpf, 'FROM: [email protected]');

Thus $vemail will receive the message, sent by [email protected] . I believe this is enough. But depending on where you are running PHP there may be other problems, some shared hosting, for example, may not allow sending or require additional settings. If you are in localhost you may also need to set up . If you are very unlucky, the domain itself, the DNS, can define who is authorized to send the email, which causes some email providers to ignore the sent message.

There are other problems in the code, in the way that both a MySQL Injection and a spam abuse are allowed. But that's out of the question.

    
20.10.2017 / 06:11