Fatal error: Call to a member function isEnabled() on a non-object in .../Swift.php on line 407
It is checking if the log is enabled - swift has it set to null so I am unsure as to why swift would be trying to make that call? I don't have to use logging do I?
Using php 5.2.2... Swift class is wrapped in my custom class...
require(ADMIN_ROOT . '/includes/swift_mailer/Swift.php');
require(ADMIN_ROOT . '/includes/swift_mailer/Swift/Connection/NativeMail.php');
require(ADMIN_ROOT . '/includes/swift_mailer/Swift/Connection/SMTP.php');
require(ADMIN_ROOT . '/includes/swift_mailer/Swift/Connection/Sendmail.php');
class Mailer extends Swift {
var $mailer;
var $message;
function Mailer() {
global $config;
if ($config['DELIVERY_METHOD'] == 'php')
$conn =& new Swift_Connection_NativeMail();
else if ($config['DELIVERY_METHOD'] == 'sendmail')
$conn =& new Swift_Connection_Sendmail(SWIFT_SENDMAIL_AUTO_DETECT);
else if ($config['DELIVERY_METHOD'] == 'smtp') {
$conn =& new Swift_Connection_SMTP($config['SMTP_HOST'], $config['SMTP_PORT']);
if ($config['SMTP_USER'] != '') {
$conn->setUsername($config['SMTP_USER']);
$conn->setPassword($config['SMTP_PASS']);
}
}
$this->mailer =& new Swift($conn);
$this->message =& new Swift_Message();
if ($config['BOUNCE_METHOD'] != 'none')
$this->message->setReturnPath($config['BOUNCE_EMAIL']);
}
}
/**
* Constructor
* @param Swift_Connection The connection object to deal with I/O
* @param string The domain name of this server (the client) as a FQDN
* @param int Optional flags
* @throws Swift_ConnectionException If a connection cannot be established or the connection is behaving incorrectly
*/
public function __construct(Swift_Connection $conn, $domain=false, $options=null)
{
$this->initializeEventListenerContainer();
$this->setOptions($options);
Swift_ClassLoader::load("Swift_Log_DefaultLog");
$this->setLogger(new Swift_Log_DefaultLog());
if ($this->hasOption(self::ENABLE_LOGGING)) $this->log->enable();
Ah I see, you're using the PHP4 version with PHP5. If you can do so, use the PHP5 version since I'm following the GoPHP5.org initiative and dropping PHP4 support in February 2008.
/**
* Constructor
* @param Swift_Connection The connection object to deal with I/O
* @param string The domain name of this server (the client) as a FQDN
* @param int Optional flags
* @throws Swift_ConnectionException If a connection cannot be established or the connection is behaving incorrectly
*/
function Swift(&$conn, $domain=false, $options=null)
{
//Do I really have to check for simpletest stuff here??
if (!is_a($conn, "Swift_Connection") && !is_a($conn, "SimpleMock"))
{
trigger_error("Swift requires constructor parameter 1 to be instance of Swift_Connection.");
return;
}
$this->initializeEventListenerContainer();
$this->setOptions($options);
Swift_ClassLoader::load("Swift_Log_DefaultLog");
$this->setLogger(new Swift_Log_DefaultLog());
if ($this->hasOption($this->ENABLE_LOGGING)) $this->log->enable();
/**
* Set the logger to use
* @param Swift_Log The instantiated logger
*/
function setLogger(&$logger)
{
if (!is_a($logger, "Swift_Log"))
{
trigger_error("Swift::setLogger requires parameter 1 to be instance of Swift_Log.");
return;
}
$this->log =& $logger;
}
Unless that error in setlogger() ever gets thrown I can't really see how it would ever be a non-object without modification of the source code. Do you have set_error_handler() anywhere?
Weird... I don't recall changing a single thing, but now my error is:
Fatal error:
Uncaught Error of type [Swift_Connection_Exception] with message [There was a problem reading line 1 of an SMTP response. The response so far was:
[]. It appears the connection has died without saying goodbye to us! Too many emails in one go perhaps? (fsockopen: #0) ]
@0 require() in \msg_send_queue.php on line 80
@1 Mailer::Mailer() in \includes\msg_send.inc.php on line 15
@2 Swift::Swift() in \includes\mailer.class.php on line 27
@3 Swift::connect() in \includes\swift_mailer\Swift.php on line 111
in \includes\swift_mailer\Swift\Errors.php on line 99
Kaitlyn2004 wrote:Unfortunately at this point I NEED to support PHP4...
there is no other call to set_error_handler appart from in /Swift/BatchMailer.php
Should I be making a specific call to load/enable logging, or what?
No you shouldn't need to do anything if you don't want to use logging. This is very odd and not something anyone else has brought up. Is this something that is reproduced every time you run the code? If so, could you private message, or email me a copy of the code so I can have a play with it?
I assume you've got swift working generally on the same server before you wrote the wrapper class?
There are various reasons for non-rceipt of a message, but generally it boils down to spam blockers and/or blacklists. What domain did you send to? Without certain network configurations hotmail, yahoo and gmail are quite tricky -- hotmail in particular.
Have a read over this, in particular the blacklisting and the SPF record: