Page 1 of 1

error message when trying using this code

Posted: Sun Dec 23, 2007 3:06 pm
by paulus4605
Dear
whn I use this code I get the following error message
what do I need to correct in my script to correct this

Code: Select all

<?php
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
$swift =& new Swift(new Swift_Connection_SMTP("smtp.myhost"));
$swift->log->enable();
$from = new Swift_Address ('myemail@gmail.com', 'webmaster ');
$subj = 'nieuwsbrief';
$body = 'my body ';
$msg = new Swift_Message ($subj, $body, 'text/html'); 
require_once('init.php');
$recipients = new Swift_RecipientList();
    $sql = "
        SELECT naam, email
        FROM testmail
        ORDER BY naam ASC
        ";
    if (!$res = mysql_query ($sql)) {
        trigger_error (mysql_error ());
    }
    else {
        while ($row = mysql_fetch_assoc ($res)) {
            $recipient = new Swift_Address ($row['email'], $row['naam']);
            $recipients->addTo ($recipient);
        }
        // en verzenden maar die hap
$num_sent = $swift->send($msg, $recipients, $from);
 //$errors = $swift->getFailedRecipients();
echo "Message sent to $num_sent of 2 recipients";
 
echo "Failed recipients:<br />";
echo implode(" ,", $swift->log->getFailedRecipients());
    }
    
?>
the error message that I get is this one :
Notice: Undefined property: Swift::$log in D:\workspace\indiana\gallery\batch.php on line 5

Fatal error: Call to a member function enable() on a non-object in D:\workspace\indiana\gallery\batch.php on line 5

thanks for your help

Posted: Sun Dec 23, 2007 3:11 pm
by John Cartwright
Sounds like your using a newer version of Swift with the old implementation of the logger.

According to, http://swiftmailer.org/wikidocs/v3/misc/logging
NOTE: In Versions 3.0, 3.1 and 3.2 logging did exist, but it was less useful, residing only as a property in $swift→log with only “on” or “off” states. The API documentation for these earlier versions provides rudimentary documentation for usage.
Also, check out that link on how to properly implement the log.

Posted: Mon Dec 24, 2007 12:52 am
by paulus4605
jcart
I'm sorry but I can't find the exact places where to change this, since I'm new to swiftmailer and want to avoid changing something that I shouldn't change, can you help me out here what I need to do in order to make this work?
thanks

Paul[/i]

Posted: Tue Dec 25, 2007 6:09 am
by paulus4605
can someone please help me out here
thanks for your help
kind regards

Posted: Wed Dec 26, 2007 4:31 pm
by Chris Corbyn
I need to update the documentation. All that's happened is that the log got moved between versions. The documentation is out of date :oops:

Replace:

Code: Select all

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

//with

$log =& Swift_LogContainer::getLog();
implode(" ,", $log->getFailedRecipients());