Page 1 of 1

Howto: Error log into database

Posted: Sat Feb 23, 2008 9:57 am
by Terradon
This is really the best mail library i have ever seen!
Easy to setup and needed just a few lines to integrate and to get it working with my application!

I use it for a newsletter service and it works perfect, but......
some users have a huge amount of rejected (validated by opt-in!!) email addresses.
In some cases 50%. I checked them, but they are all normal addresses. And again, these addresses are already validated by an opt-in system.

I want to turn on the Swift's Logging System, cause Swift marks them rejected by mailserver??
For better understanding what is happening, i want to turn on the logging system. But i dont want to show the results on screen by echo $log->dump(true);
I want to add the error message into my database (=errorlog).
Which variable do i have to insert into my database?

this is part of the code i use for html newsletters:

//Now check if Swift actually sends it
if ($swift->send($message, $to, new Swift_Address($sender, $senderName)))
{
// On succes: Update flag 0->1
$sql4 = "UPDATE NB_html_wachtrij SET flag = 1 WHERE sentID = ".$sentID;
mysql_query($sql4) or die(mysql_error());
$i = $i + 1;
}
else
{
//On error change: Update flag 0->9
$sql4 = "UPDATE NB_html_wachtrij SET flag = 9 WHERE sentID = ".$sentID;
mysql_query($sql4) or die(mysql_error());

// Add to logbook!
$i_errors = $i_errors + 1;
$txt = $to.' Adres kon niet aan mail server doorgegeven worden (HTML nieuwsbrief)';
$sql_log = "INSERT INTO terra_logboek (userID,cat,txt,datetime) VALUES
('".$userID."','error','".$txt."',NOW())";
$result2 = mysql_query($sql_log) or die(mysql_error());
}

I use this code in a whileloop for max of 50 mails per cronjob.
In case of an error i set flag=9, so it wont be sent anymore.

Unfortunately i dont understand which variable i need to insert for a message from the swift logging system.

Re: Howto: Error log into database

Posted: Tue Feb 26, 2008 12:16 pm
by Terradon
Hi again.

I added the error message like:

//On error change: Update flag 0->9
$sql4 = "UPDATE NB_html_wachtrij SET flag = 9 WHERE sentID = ".$sentID;
mysql_query($sql4) or die(mysql_error());

//$log =& Swift_LogContainer::getLog();
//echo $log->dump(true);
$swiftErrortxt = htmlentities($log->dump(true));

// Add to logbook!
$i_errors = $i_errors + 1;
$txt = $to.' Adres kon niet aan mail server doorgegeven worden (HTML nieuwsbrief)<br>'.$swiftErrortxt;
$sql_log = "INSERT INTO terra_logboek (userID,cat,txt,datetime) VALUES ('".$userID."','error','".$txt."',NOW())";
$result2 = mysql_query($sql_log) or die(mysql_error());


This is the routine which flags the message to 9 (not deliverded to mailserver)
The only error message i get is: ++ Log level changed to 4
nothing more!!

Please help,
a desperade webmaster...