php – sendmail() localhost in BATCH

Question:

Friends, I am able to send email normally using sendmail() localhost, as follows:

sendmail.ini

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
smtp_ssl=auto
auth_username=meugmail
auth_password=minhasenha

smtp_ssl=tls
tls_certcheck off

php.ini

[mail function]

SMTP = smtp.gmail.com
smtp_port = 465
sendmail_from = meugmail
sendmail_path = "C:\"\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header = Off

When sending, I search a specific table in my bank, where the messages are recorded, and I send them one by one, something like this:

$sqlemail = $mysqli->prepare("SELECT id_email, id_msg, id_remetente, id_destinatario, tipo_destinatario, email, assunto, 
                              texto, arquivo_anexo, data FROM tbl_msg_email_temp LIMIT 1");
$sqlemail->execute();
$sqlemail->store_result();

if($sqlemail->num_rows > 0){//Achei emails há serem enviados

    $sqlemail->bind_result($id_email, $id_msg, $id_remetente, $destinatario, $tipo, $email_user, $assunto, $texto, $arquivo_anexo, $data);
    $texto =  nl2br($texto);
    $sqlemail->fetch();
    $sqlemail->close();

So once I find one or more msgs to be sent, I'll send them one by one with the mail() function.

if (mail($to, $assuntoHTML, $mensagem, $headers)) {

As I said, this works perfectly, but now I've come across the possibility of sending the same msg to several people, and as it is, I must connect to google every time making the process very slow, I would really like to connect once and send the 1,000, 10,000 msgs.

it is possible ?

thanks.

Answer:

According to the answer found in SOEN , you could send the same message to multiple recipients as follows:

while($row = mysql_fetch_array($result))
{
    $addresses[] = $row['address'];
}

$to = implode(", ", $addresses);

$headers .= "BCC: {$to} \r\n";

mail(null, $assuntoHTML, $mensagem, $headers);
Scroll to Top