PHPMailer -> flere modtagere i Array FRA sql
Jeg har i dag et script som jeg har modificeret således at det så udemærket sender mail's til dem som jeg har manuelt skrevet i ind, men hvordan inkluderer jeg automatisk flere modtagere således at Array bliver trukket direkte fra en DB?<?php
include "class.smtp.php";
include "class.phpmailer.php";
$Host = "mail.yourdomain.com"; // SMTP servers
$Username = "your-smtp-username@yourdomain.com"; // SMTP password
$Password = "your-smtp-password"; // SMTP username
$From = "from-email@yourdomain.com";
$FromName = "From Name";
$Tos = array(
"To Name 1" => "to-email-1@4rapiddev.com",
"To Name 2" => "to-email-2@gmail.com"
);
$Ccs = array(
"CC Name 1" => "cc-email-1@yahoo.com",
"CC Name 2" => "cc-email-2@gmail.com"
);
$Subject = "Hello there";
$Body = "This is a test email which will send to multiple recipients";
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = $Host;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = $Username;
$mail->Password = $Password;
$mail->From = $From;
$mail->FromName = $FromName;
foreach($Tos as $key => $val){
$mail->AddAddress($val , $key);
}
foreach($Ccs as $key => $val){
$mail->AddCC($val , $key);
}
$mail->WordWrap = 50; // set word wrap
$mail->Priority = 1;
$mail->IsHTML(true);
$mail->Subject = $Subject;
$mail->Body = $Body;
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo 'Message has been sent.';
}
?>
Ovenstående er "blot" en standard metode for at sende SMTP mail via php, men hvordan smider jeg et DB Array ind i det?