0
Hello, I’m having a problem, I’m trying to get phpmailer to send an email to several recipients at the same time, but only appear para:[email protected]
just that and without showing the other emails that were sent how to do this?
function get_emails($con){
$sql = $con->prepare("SELECT * FROM cadastros");
$sql->execute();
$get = $sql->get_result();
$total = $get->num_rows;
if($total > 0){
$id = 0;
while ($dados = $get->fetch_row()) {
$rows[] = $dados['1'];
}
foreach($rows as $key){
$id ++;
if($id < $total){
$emails = $key." ";
}else if($id>1){
$emails = $key;
}
}
}
}
function send_mail($con){
if(isset($_POST['env']) && $_POST['env'] == "email"){
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = '[email protected]';
$mail->Password = 'senha';
$mail->Port = 587;
$mail->setFrom('[email protected]', 'Stephanto');
$destinos = get_emails($con);
$mail->addAddress($destinos);
$mail->addReplyTo('[email protected]');
$mail->isHTML(true);
$mail->Subject = $_POST['assunto'];
$mail->Body = '<div style="borger:2px solid red;"></div>';
if(!$mail->send()){
echo "<div class='alert alert-danger'>Erro ao enviar o E-mail! </div><br>";
echo "Erro: ".$mail->ErrorInfo;
}else{
echo "<div class='alert alert-successes'>E-mail enviado com sucesso! </div>";
}
You could create a function that sends an email only. Just put a loop like
foreach($emails as $email){...}
– Breno
i am beginner in programming could explain better? grateful
– Stephanto