error message when trying using this code

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
paulus4605
Forum Newbie
Posts: 12
Joined: Mon Jun 04, 2007 2:50 pm

error message when trying using this code

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
paulus4605
Forum Newbie
Posts: 12
Joined: Mon Jun 04, 2007 2:50 pm

Post 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]
paulus4605
Forum Newbie
Posts: 12
Joined: Mon Jun 04, 2007 2:50 pm

Post by paulus4605 »

can someone please help me out here
thanks for your help
kind regards
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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());
Post Reply