PHPMailer - 从数据库发送电子邮件

时间:2017-09-10 20:49:56

标签: php email phpmailer mailer

我试图创建一个脚本,在执行时使用邮件正文向我的客户端发送电子邮件,但是当它执行时它永远不会有效。

$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>";
        }
    }
}

我失踪了什么?

0 个答案:

没有答案