How to loop to send my emails?

0

I'm trying to make the code pick up the emails I'm going to put in a .txt or a form list (while I'm not setting up the database) and loop to send all the emails. It turns out I'm getting this error message and I do not know how to fix the problem.

<?PHP

require_once('class.phpmailer.php');

$nm = $_GET['nome'];
$sb = $_GET['sobrenome'];

$address = "[email protected]";
$address = "[email protected]";

for($loop=0; $loop<4; $loop++){

  $mail = new PHPMailer();
  $body = file_get_contents('a.html');


  $mail->AddReplyTo("[email protected]","EREA SSA");
  $mail->SetFrom('[email protected]', 'EREA SSA');


  // Nome e Sobrenome pegos através do GET "site.com/email.php?nome=André&sobrenome=Leal"
  $mail->AddAddress($address[$loop], utf8_decode("$nm[$loop] $sb[$loop]"));
  $mail->Subject = "Teste !";
  $mail->MsgHTML($body);

  //$mail->AddAttachment(""); // Arquivos para anexo

  if(!$mail->Send()) {
    echo "Erro: " . $mail->ErrorInfo . "<br/>";
  } else {
    echo "Mensagem enviada !";
  }
  $mail->clearAllRecipients(); // Limpa o campo de para quem o email será enviado e o nome

}

?>
    
asked by anonymous 24.12.2015 / 01:54

1 answer

0

Well, the solution has already been found, right down to the problem solution for anyone who wants to use it to study.

<?PHP

require_once('class.phpmailer.php');

$nm = $_GET['nome'];
$sb = $_GET['sobrenome'];

$address[] = "[email protected]";
$address[] = "[email protected]";
$address[] = "[email protected]";
$address[] = "[email protected]";

foreach($address as $addr){

  $mail = new PHPMailer();
  $body = file_get_contents('a.html');

  $mail->AddReplyTo("[email protected]","Opa Epa");
  $mail->SetFrom('[email protected]', 'Opa Epa');

  $mail->AddAddress($addr, utf8_decode("$nm[$loop] $sb[$loop]"));
  $mail->Subject = "Teste !";
  $mail->MsgHTML($body);

  //$mail->AddAttachment(""); // Arquivos para anexo

  if(!$mail->Send()) {
    echo "Erro: " . $mail->ErrorInfo . "<br/>";
  } else {
    echo "Mensagem enviada !<br/>";
  }
  $mail->clearAllRecipients(); // Limpa o campo de para quem o email será enviado e o nome

}

?>
    
24.12.2015 / 04:25