1
I am trying to send emails to specific lists registered in the database, with the php mail function but the email is not sent. What can be the mistake?
Below 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.
Where you are testing this upload, localhost or on the server?
– abfurlan
I’m testing on the server, Kinghost
– Odair
Usually shared host does not allow bulk uploading or long script runs. Some even allow bulk email sending but with limitations (200, 300 per day), for example. Consult your provider and check the signed plan conditions
– Daniel Omine
smtp ta configured for?
– Rafael Ferreira
@Rafaelferreira Yes, SMTP is configuring correctly
– Odair
Thanks @Danielomine Very important information. I will check, maybe this is it.
– Odair
the error may be the missing parameter
-f
also:mail( $destinatario, $assunto, $corpo, $headers, '-f'.$remetente );
in systems based on sendmail.– Bacco