OK… I trimmed the code in my previous reply so it would be easier to read. Here’s the code where I define $recipientAddress, $Subject, $msg, $headers and $additional:
/*** Build message as combo of hardcoded and variable parts; can also intercept some fields from input screen ***/
$AT = ‘@’;
$DOT = ‘.’;
$eol = ‘\r\n’;
$email5 = ‘Todd.Greeno’ . $AT . ‘gMail’ . $DOT . ‘com’;
$email6 = ‘Todd.Greeno’ . $AT . ‘gMail’ . $DOT . ‘com’;
$style0 = ‘BODY {font-family: Verdana; font-size: 10px; color: Navy; }’ . $eol;
$style1 = ‘TD { white-space: normal; font-size: 12px;}’ . $eol;
$style2 = “TD.data {background-color: ‘#EFE2DC’; font-family: ‘Comic Sans MS’; font-size: 13px; color: Navy; }” . $eol;
$style3 = “TD.title, th {font-family: ‘Times New Roman’; font-style: ‘italic’; font-size: 16px; color : red; font-weight: bold; background-color: ‘#EFE2DC’; }” . $eol;
$style4 = “.emph {font-family: ‘Times New Roman’; font-style: ‘italic’; font-size: 16px; color : red; font-weight: bold; }” . $eol;
$style5 = “.emph3 {font-family: ‘Comic Sans MS’; font-style: ‘italic’; font-size: 22px; color: ‘#C00000’; font-weight: normal; }” . $eol;
$style = '<style>' . $eol . $style0 . $style1 . $style2 . $style3 . $style4 . $style5 . '</style>' . $eol;
$BodyTag = "<body bgcolor=#ffffff text=navy leftmargin='0' topmargin='0'
marginwidth=‘0’ marginheight=‘0’>" . $eol;
$eoBody = “” . $eol . “” . $eol;
// -----------[ SUBJECT
$Subject = ‘A Special Holiday Greeting For You’;
$WineGlass = “<img alt=“It’s about WINE!” width=82 height=132 src=”…Images/aWineGlass2.gif">";
$result = mysqli_query($link, $newQuery) or die(mysqli_error($link));
$num = 0;
while($row = mysqli_fetch_array($result)){
$num = 1 + $num;
$recipientAddress = $email4;
$recipAddr = $row[‘EmailAddress’];
if($ProductionChecked == ‘1’) {$recipientAddress = $recipAddr;}
$RecipientName = $row[‘LastName’] . ", " . $row[‘FirstName’];
$GreetingName = $row[‘GreetingName’];
$PersMsg = $row[‘PersMsg’];
$CurrPriority = $row[‘Priority’];
$SentPriority = $CurrPriority + (10 * $CurrPriority);
$Cover1 = "<img src=../Images/CoverNYC-atNight4XmasEdit.jpg width=762 height=507>";
$InsideImage1 = "background=../Images/PortLayer.jpg";
$Signature = "<tr><td><center><img width=331 height=49 src=../Images/ProducedByGreenoCom2.gif></center></td></tr>";
$Table1 = "<table border=0 cellspacing=8 cellpadding=0><tr><td width=100 valign=top>";
$Table2 = "</td><td width=* valign=top>";
$Table3 = "</td></tr></table>";
$msgHdr = "<HTML>" . $eol . "<HEAD>" . $eol . $style . $eol . "</HEAD>" . $eol . $BodyTag . $eol;
$xmasmsg = "
<span style="font-family: ‘Comic Sans MS’; font-style: ‘italic’; font-size: 22px; color: ‘#C00000’; font-weight: normal; ">My warmest wishes this winter season for a happy and memorable and SAFE Holiday celebration that brings you close to friends, family and loved-ones.
All the best for a wonderful and SAFE New Year!
Cheers!
Todd
. " . $eol;
$msg = "";
$msg .= $msgHdr;
$msg .= "<span style=\"font-family: 'Verdana'; font-size: '12px';\">" . $eol;
$msg .= "<br /><br /><b>If you are unable to see the images below, <a target=_blank href=https://www.greeno.com/Main/MyCard.php?ADDR=" . $recipAddr . "&S=" . $iStamp . "&CVR=" . $CoverImg . "&INS=" . $InsideImg . "&SEQ=" . $CurrPriority . ">you can view your card here</a>.</b><br /><br />" . $eol;
$msg .= "<table width=762 border=1 cellspacing=0 cellpadding=0>" . $eol;
$msg .= "<tr><td class=title valign=top>" . $eol;
$msg .= "<table width=* border=0><tr><td width=20> </td><td width=* valign=top>" . $eol;
$msg .= "<table align=right border=0 width=200><tr><td valign=top>" . $Stamp . "</td></tr></table><br><span style=\"font-family: 'Times New Roman'; font-style: 'italic'; font-size: 16px; color : red; font-weight: bold; \"><i>" . $eol;
$msg .= "In previous years, I designed Holiday cards that were printed on recycled paper, but sending them still expended a lot of resources in printing and in using the US Postal service to make the door-to-door deliveries... This year, I am continuing the \"greener\" approach I started over a decade ago with this electronic version that still has my unique custom design and my personal message to you." . $eol;
$msg .= "</i></span><br>" . $eol;
$msg .= "</td></tr></table>" . $eol;
$msg .= "</td></tr>" . $eol;
$msg .= "<tr><td>" . $Cover . "</td></tr>" . $eol;
$msg .= "<tr><td class=data " . $InsideImage . " height=490 valign=top>" . $eol;
$msg .= "<table width=* border=0 align=top><tr><td width=20> </td><td width=* valign=top>" . $eol;
$msg .= "<span style=\"font-family: 'Comic Sans MS'; font-style: 'italic'; font-size: 22px; color: '#C00000'; font-weight: normal; \"><i><br>" . $eol;
$msg .= $PersMsg . $eol;
/-----------------[CHRISTMAS CONTENT --------------/
$msg .= $xmasmsg ;
/---------------------------------------------------/
$msg .= $Signature . $eol;
$msg .= "</td></tr></table>" . $eol;
$msg .= "<br><br>" . $eol;
$msg .= "</span>" . $eol;
$msg .= $eoBody;
$headers2 = ‘From: Todd Greeno <’ . $email6 . ‘>’ . $eol;
$headers2 .= ‘Reply-to: Todd Greeno <’ . $email6 . ‘>’ . $eol;
$headers2 .= ‘Return-Path: Todd Greeno <’ . $email6 . ‘>’ . $eol; // these two to set reply address
$headers2 .= 'Message-ID: ’ . sprintf("<%s.%s@%s>",
base_convert(microtime(), 10, 36),
base_convert(bin2hex(openssl_random_pseudo_bytes(8)), 16, 36),
‘myURL’) . $eol;
$headers2 .= ‘X-Mailer: PHP v’ . phpversion() . $eol; // These two to help avoid spam-filters
$headers2 .= ‘Content-type: text/html; charset=us-ascii’ . $eol;
$headers = $headers2;
$additional = ‘-r’ . $email6 ;
if (mail($recipientAddress,$Subject,$msg,$headers,$additional)) {
$ResultMsg .= “” . $CurrPriority . "Sent to: " . $RecipientName . “” . $recipientAddress . “” . $eol;
$Counter = $Counter + 1;
$uQuery=“UPDATE Recipients SET DateSent=CURDATE(), Priority=$SentPriority WHERE EmailAddress=’$recipientAddress’”;
mysqli_query($link, $uQuery);
sleep(8);
} else {
$ErrorTrap .= "NOT Sent: " . $RecipientName . “” . $recipientAddress . “” . $eol;
$Failed = $Failed + 1 ;
}
//There’s a lot more code with error checks, and a few status echos to the screen…
//So instead of The if/else section above, should I use:
/ Set up new PHPmailer connection and set to SMTP version
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = ‘ssl’; // secure transfer enabled REQUIRED for Gmail
$mail->Host = “smtp.gmail.com”;
$mail->Port = 465; // or 587
$mail->IsHTML(true);
//This is in a loop that selects just ONE Recipent… ( Set up recipient info which is just an email address )
$mail->AddAddress( $row[‘EmailAddress’] );
// Set up user information and server information
$mail->Username = “[" . $email5 ."](mailto:" . $email5 .")”;
$mail->Password = “my gMail PW”;
$mail->SetFrom(" 'From: Todd Greeno [" . $email5 ."](mailto:" . $email5 .")”;
$mail->Subject = $Subject;
$mail->Body = $msg;
//Send message to current recipient
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo “Message has been sent”;
}
//End of loop
}