I am using the code below to send emails out to a mailing list using PHPmailer. right now i cant get the code to work. is the way im doing it correct or is there a better way. the code below is a cobmination of code ripped from another app and my own code.
if ($_POST[issending] == "yes"){
$eventTitle = $_POST['eventTitle'];
$eventId = $_POST['eventId'];
$eventMessage = $_POST['eventMessage'];
$runningtally = $_POST['runningtally'];
/////////////////send the emails out///////////
///counter sets the start point of query
///count is running tally of emails sent
///count2
$count=0;
include("inc/MailerClass.php");
//require ("inc/MailerClass.php");
$mailer = new eMailer;
$mailer->Subject = "YOU HAVE BEEN SENT AN INVITATION FROM ". $config['sitename']."";
// HTML body
$htmlBody = "$lang[email_sentmessage]: $eventTitle\n";
$htmlBody .= "$eventMessage\n";
$htmlBody .= "$lang[email_msg1]\n\n";
$htmlBody .= "$config[installdir]/viewevent.php?eventId=$eventId\n";
$htmlBody .= "$lang[email_msg12]";
// Plain text body (for mail clients that cannot read HTML)
$textBody = "$lang[email_sentmessage]: $eventTitle\n";
$textBody .= "$eventMessage\n";
$textBody .= "$lang[email_msg1]\n\n";
$textBody .= "$config[installdir]/viewevent.php?eventId=$eventId\n";
$textBody .= "$lang[email_msg12]";
$mailer->Body = stripslashes($htmlBody);
$mailer->AltBody = stripslashes($textBody);
$mailer->IsHTML(true);
//$mailer->WordWrap = 75;
$mailer->UseMSMailHeaders = true;
$mailer->AddCustomHeader("X-Mailer: Email Interface");
echo "<b>Send Newsletter</b><br><br>\n";
if ($runningtally == "") {
$runningtally=0;
}
$query = "SELECT * FROM usereventmap WHERE eventId='$eventId' LIMIT $runningtally, 2";
$result = mysql_query($query) or die("<b>aaaA fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
while ($row = mysql_fetch_array($result)) {
if (! get_cfg_var('safe_mode')) {
set_time_limit(0);
}
$userarray = getUserInfo ($row['userId']);
$mailer->AddAddress("$userarray[emailAddress]","");
if(!$mailer->Send()) {
echo "There was an error sending the message to ". $userarray['emailAddress'] ." !!!<br>";
} else {
echo "Mail to ".$userarray['emailAddress']." <b>sent</b>!<br>";
}
flush();
$mailer->ClearAllRecipients();
echo "count before $count<br>";
echo "count2 before $count2<br>";
echo "counter before $counter<br>";
$runningtally++;
$count++;
if ($count == 2) {
echo "<small>... sending in progress - please be patient ...</small>";
echo "<form method=\"POST\" name=\"form\" id=\"form\" action=\"$PHP_SELF\">
<input type=hidden name=\"issending\" value=\"yes\">
<input type=hidden name=\"runningtally\" value=\"$runningtally\">
</form>
<script language=javascript>document.form.submit();</script>";
}else {
echo "DONE sending emails";
}
}//end while
}else{
do something
}
echo "<br>$runningtally emails sent.<br>\n";