1

I'm trying to create a script that will sent e-mail to my clients when executed, with a mail body, but when it executes it never works.

$mail = new PHPMailer();
if ($config['site']['smtp_enabled']) {
    $mail->IsSMTP();
    $mail->Host = $config['site']['smtp_host'];
    $mail->Port = (int)$config['site']['smtp_port'];
    $mail->SMTPAuth = $config['site']['smtp_auth'];
    $mail->Username = $config['site']['smtp_user'];
    $mail->Password = $config['site']['smtp_pass'];
    $mail->SMTPSecure = "tls";
} else {
    $mail->IsMail();
}

$mailList = mysqli_query($conn, "SELECT email FROM accounts");
$emailSent = 0;
$emailValido = 0;

foreach ($mailList as $tmpEmail => $mailling) {
    if (filter_var($mailling['email'], FILTER_VALIDATE_EMAIL)) {
        $mail->IsHTML(true);
        $mail->From = $config['site']['mail_address'];
        $mail->AddAddress($mailling['email']);
        $mail->Subject = "Teste";
        $mail->Body = $mailBody;
        $emailValido++;

        if ($mail->Send()) {
            $emailSent++;
            echo $emailSent . " - Enviado para ".$mailling['email'].".<br>";
        }
    }
}

What I'm missing?

vankk
  • 77
  • 7
  • Does it give an error? Did you configure SMTP host/ip, username, password, etc? Is this only part of the script, if so, can you pls share what is missing? – Malbordio Sep 10 '17 at 21:16
  • @rtfm doesn't look a duplicate to me. Different script, diferent parameters. – Malbordio Sep 10 '17 at 21:18
  • well its never going to 100% identical is it, the principal and solutions are the same however –  Sep 10 '17 at 21:20
  • 1
    I don't think it's even 50% identical. This form does not call another form like the other script, post method is diffent. On this script mail function is present, in the other is not... hence, many diferences so far. Although something is fishy on this script and is not included the whole code. – Malbordio Sep 10 '17 at 21:27
  • focus on the answer not the question. its the go to we always use for this kind of question. –  Sep 10 '17 at 21:40
  • The script doesn't give any kinda of error, it just doesn't work. The SMTP is configured, maybe is the way that I'm trying to send the emails, I mean, by using foreach loop. – vankk Sep 10 '17 at 22:39
  • Base your code on [the mailing list example provided with PHPMailer](https://github.com/PHPMailer/PHPMailer/blob/master/examples/mailing_list.phps). Overall it looks like you're doing most things right, but you need to show what exactly is not working; we can't guess - stick some debug output or breakpoints in your code - for example it would do nothing if your DB connection is broken. That other question is clearly not a duplicate - it's not using PHPMailer, and its principle and solutions are not the same at all. – Synchro Sep 11 '17 at 06:40

0 Answers0