Page 1 of 1

swift->log->enable()

Posted: Wed Mar 12, 2008 2:34 pm
by noury7
Hallo everyone,
I use swiftmailer. i want to enable logging to catch the failed addresses. version is Swift-3.3.2-php5

the code
-----------------------------
require_once "swiftLib/Swift.php";
require_once "swiftLib/Swift/Connection/SMTP.php";

try {
$swift = new Swift(new Swift_Connection_SMTP("smtp.casema.nl"));
$from = new Swift_Address ($from, $sender);

$swift->log->enable();

//Create the message
$message = new Swift_Message($newslettersTitle, $newslettersContent);
$message->setContentType("text/html");

//Now check if Swift actually sends it
$recipients = new Swift_RecipientList();

foreach ($emails as $emails) {

$recipients->addTo($emails['customersemailaddress']);
//NOTE that Cc and Bcc recipients are IGNORED in a batch send
}
$this->view->nbrEmailsSent = $swift->batchSend($message, $recipients, $from);

echo implode(" ,", $swift->log->getFailedRecipients());

return true;
} catch (Swift_ConnectionException $e) {
echo "There was a problem communicating with SMTP: " . $e->getMessage();
return false;

} catch (Swift_Message_MimeException $e) {
echo "There was an unexpected problem building the email:" . $e->getMessage();
return false;
}
//-------- end swiftMailer------------//
------------------------------

But i get this terrible error.

Notice: Undefined property: Swift::$log in D:\www\zf_webwinkel-1.0.4-RC1\application\modules\admin\controllers\NewslettersController.php on line 172

Fatal error: Call to a member function enable() on a non-object in D:\www\zf_webwinkel-1.0.4-RC1\application\modules\admin\controllers\NewslettersController.php on line 172

does anyone know what is going on

Regards Nour

Re: swift->log->enable()

Posted: Wed Mar 12, 2008 11:03 pm
by Chris Corbyn
I think a page in my documentation is out of date. The way to do it now is:

Code: Select all

$log =& Swift_LogContainer::getLog();
$log->setLogLevel(4);
 
// put all the code here
 
echo '<pre>' . htmlentities($log->dump(true)) . '</pre>';