Problems sending php email

1

I'm trying to send emails to specific lists registered in the database, with the mail function of php but the email is not sent. What could be the error?

Below is the script for sending emails:

if ($_SERVER["REQUEST_METHOD"] == "POST"){
    //realiza a conexão com o banco de dados
    require_once("includes/conexao.php");
    //monta o corpo da mensagem
    $corpo                  = file_get_contents("$_POST[mensagem]");
    //lista de e-mails que será enviada
    $lista                  = $_POST["lista"];
    //remetente (e-mail de quem envia)
    $remetente              = $_POST["remetente"];
    //pega o domínio do remetente
    $dominio                = substr(strrchr($remetente, "@"), 1);
    //assunto da mensagem
    $assunto                = $_POST["assunto"];

    //realiza o envio dos emails
    $sql                    = "SELECT DISTINCT email FROM dados WHERE lista = '".$lista."'";
    $query                  = mysqli_query($conexao, $sql);
    while($exibir           = mysqli_fetch_array($query)){
        //headers
        $destinatario       = $exibir["email"];
        $headers            = "MIME-Version:1.1"."\n";
        $headers           .= "Content-type: text/html; charset=utf-8"."\n";
        $headers           .= "To: <$destinatario>"."\n";
        $headers           .= "From: Teste de envio"."\n";
        $headers           .= "Reply-To: <no-reply@$dominio>"."\n";
        $headers           .= "Return-Path: <$remetente>"."\n";
        $envio              = mail($destinatario, $assunto, $corpo, $headers);
    }

Note: No error is returned.

    
asked by anonymous 19.04.2016 / 22:19

1 answer

1

First try forcing to show the errors:

<?php

    ini_set('display_errors','On');
    error_reporting(E_ALL);

It may also be that the mail () function is disabled in kinghost, for several reasons, one of them is spam.

I advise you to use PHPMailer, to send via SMTP, it is safer and your email will not risk falling into the spam box too.

    
19.04.2016 / 22:49