Script PHP de envio de email no PHPMailer usando uma lista de endereços

<?php

//Import the PHPMailer class into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;

require_once("vendor/autoload.php");



$listas = file("/var/www/html/testemail/contas");

foreach($listas as $usuario)
{

//echo ($usuario);
/**
 * This example shows making an SMTP connection without using authentication.
 */
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// SMTP::DEBUG_OFF = off (for production use)
// SMTP::DEBUG_CLIENT = client messages
// SMTP::DEBUG_SERVER = client and server messages
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
//Set the hostname of the mail server
$mail->Host = 'antispam.seati.ma.gov.br';
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = '25';

if ($mail->Port == 465)
        $mail->SMTPSecure = "ssl";
        $mail->SMTPAuth = 'true';
        $mail->SMTPOptions = array(
                    'ssl' => array(
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                        'allow_self_signed' => true
                )
        );

if ($mail->Port == 587)
//Set the encryption mechanism to use - STARTTLS or SMTPS
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
//Whether to use SMTP authentication
        $mail->SMTPAuth = true;
#$mail->SMTPSecure = 'ssl';
if ($mail->Port == 25)
        $mail->SMTPAuth = false;
//Whether to use SMTP authentication
#$mail->SMTPAuth = 'true';
#$mail->SMTPOptions = array(
#                    'ssl' => array(
#                        'verify_peer' => false,
#                        'verify_peer_name' => false,
#                        'allow_self_signed' => true
#                    )
#                );
//Username to use for SMTP authentication
//$mail->Username = 'contato@exemplo.com';
$mail->Username = ($usuario);
//Password to use for SMTP authentication
$mail->Password = 'senha123';
//Set who the message is to be sent from
#$mail->setFrom('teste@seati.ma.gov.br', 'Teste suporte SEATI');
$mail->setFrom($usuario, $usuario);
//Set an alternative reply-to address
$mail->addReplyTo('contato@exemplo.com', 'Liste de administradores do email');
//Set who the message is to be sent to
$mail->addAddress('contato@exemplo.com', 'Teste Suporte SEATI');
//Set the subject line
if ($mail->Port == 465)
        $mail->Subject = 'Script de envio de emails com SMTPS (SSL) - INFRA SEATI';

if ($mail->Port == 587)
        $mail->Subject = 'Script de envio de emails com STARTTLS - INFRA SEATI (sistemas)';

if ($mail->Port == 25)
        $mail->Subject = 'Script de envio de emails SMTP padrão - INFRA SEATI';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), _DIR_);
//Replace the plain text body with one created manually
$mail->Body = 'Esse é um email de teste do script de envios em lote de mensagens';
$mail->CharSet = 'UTF-8';
//$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors
if (!$mail->send()) {
    echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;

} else {
    sleep(15);
}



}
echo 'All Messages sent!';
?>

Comentários

Postagens mais visitadas deste blog

PYTHON - ENVIAR MENSAGEM VIA TELEGRAM

Dicas Zimbra

ZIMBRA - BACKUP CONTAS DE EMAILS FECHADAS A MAIS DE 90 DIAS