I’m using PHPMailer to send out multiple emails but if I use AddAddress, it will clump all of the emails into multiple TO: values, and if I use AddBCC the email addresses are hidden but there is no personalization.
So in a nutshell I want to send out multiple emails from emails in a database and each email to have a personal TO: field including their email address and name. Is this even possible or would I have to do multiple mail() calls? I substituted my own domain with domain.com but otherwise the same as what I have.
Here is a sample of the script:
// Get campaign email body
$csubject = $_REQUEST['csubject'];
$cbody = $_REQUEST['cbody'];
$campid = $_REQUEST['campaign'];
// Query the database for email addresses
$result = mysql_query("SELECT * FROM ecampaigns_test WHERE campaign=$campid");
// Include PHPMailer script
include('inc/phpmailer/class.phpmailer.php');
// Start PHPMailer code
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->SetFrom('info@domain.com', 'Domain.com');
$mail->Subject = "$csubject";
// Start Loop of sending emails
while ($row = mysql_fetch_array ($result)) {
$mail->AltBody = "To view the message, please use an HTML compatible email viewer"; // optional, comment out and test
$mail->MsgHTML("Dear ".$row["fname"].",<br>".$cbody);
$mail->AddAddress($row["email"], $row["fname"]);
}
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "<span style=\\"font-weight:bold; font-size:110%\\">Email campaign has been sent.</span><br><br><a href=\\"/admin\\">Return to Admin</a>";
}