Sendmail() BATCH localhost

Asked

Viewed 77 times

3

Friends, I am being 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 do a search in a specific table of my bank, where messages are recorded, and I send one by one more or less 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();

Then once one or more msgs are located to be sent, I send them one by one with the mail function()

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

Like I said, this works perfectly, but now I’ve come across the possibility of sending the same msg to several people, and the way it is, I must connect to google every time by slowing the process down, i would really like to connect once and send the 1,000, 10,000 msgs.

this is possible ?

thank you.

1 answer

1

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);
  • This will create an email chain.

  • Ah, there’s a way to send a CCO. But I forgot :\

  • Goes no $headers, if I’m not mistaken it’s $headers .= "Bcc: $to \r\n";

  • Fixed, buddy, @rray

  • I understood, in the case of the same msg, if it is personalized msgs, you could tell me how to send to many by connecting once to GMAIL ?

  • 1

    Friend, you can simply use classes ready for this purpose. Take a look at Swift Mailer, it is very easy to send an email via g-mail (with only one connection) and it is easier to structure the code!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.