Catchable fatal error: Argument 1 passed to Swift_Transport

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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Benjamin »

Not sure what I did wrong here. I'm getting all sorts of errors.

Code: Select all

 
$transport = Swift_SmtpTransport::newInstance(sfConfig::get('sf_smtp_host'), sfConfig::get('sf_smtp_port'))
    ->setUsername(sfConfig::get('sf_smtp_user'))
    ->setPassword(sfConfig::get('sf_smtp_pass'))
;
 
$mailer = SwiftMailer::newInstance($transport);
 
$message = Swift_Message::newInstance('Subject')
    ->setFrom(array('john@doe.com' => 'John Doe'))
    ->setTo(array('receiver@domain.com' => 'Receiver Name'))
    ->setBody($this->getPartial('mail/registerNewText', $members))
    ->addPart($this->getPartial('mail/registerNewHtml', $members), 'text/html')
;
 
$result = $mailer->send($message);
 
Catchable fatal error: Argument 1 passed to Swift_Transport_EsmtpTransport::__construct() must implement interface Swift_Transport_IoBuffer, none given in /home/benjamin/public_html/ldnr/lib/vendor/swift/classes/Swift/Transport/EsmtpTransport.php on line 74

Warning: Missing argument 1 for Swift_Transport_EsmtpTransport::__construct() in /home/benjamin/public_html/ldnr/lib/vendor/swift/classes/Swift/Transport/EsmtpTransport.php on line 74

Catchable fatal error: Argument 2 passed to Swift_Transport_EsmtpTransport::__construct() must be an array, none given in /home/benjamin/public_html/ldnr/lib/vendor/swift/classes/Swift/Transport/EsmtpTransport.php on line 75

Warning: Missing argument 2 for Swift_Transport_EsmtpTransport::__construct() in /home/benjamin/public_html/ldnr/lib/vendor/swift/classes/Swift/Transport/EsmtpTransport.php on line 75

Catchable fatal error: Argument 3 passed to Swift_Transport_EsmtpTransport::__construct() must be an instance of Swift_Events_EventDispatcher, none given in /home/benjamin/public_html/ldnr/lib/vendor/swift/classes/Swift/Transport/EsmtpTransport.php on line 75

Warning: Missing argument 3 for Swift_Transport_EsmtpTransport::__construct() in /home/benjamin/public_html/ldnr/lib/vendor/swift/classes/Swift/Transport/EsmtpTransport.php on line 75

etc, etc...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Chris Corbyn »

Oh.

What version of PHP are you using (exact version number)?

Looks like the dependency injection is failing completely. Did you upload the *entire* lib folder, or just the lib/classes folder?

EDIT | Also, what does this show you?

Code: Select all

var_dump(gettype(Swift_DependencyContainer::getInstance()->lookup('transport.smtp')));
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Benjamin »

Well I figured that maybe I needed to include the swift_required.php class, because perhaps the symfony autoloader wasn't loading the library correctly automatically.

I added the following line to ProjectConfiguration.class.php, which is the file for global application configuration:

Code: Select all

 
# include the swift mailer library
require_once('../lib/vendor/swift/swift_required.php');
 
And that gives me this error:
LogicException: Passed array specifies a non static method but no object in /home/benjamin/public_html/ldnr/lib/vendor/swift/swift_required.php on line 65
And the code in swift_required.php for that line is:

Code: Select all

 
function swift_autoload_register()
{
  if (!$callbacks = spl_autoload_functions())
  {
    $callbacks = array();
  }
  foreach ($callbacks as $callback)
  {
    spl_autoload_unregister($callback);
  }
  spl_autoload_register('swift_autoload');
  foreach ($callbacks as $callback)
  {
    spl_autoload_register($callback); // <-- line 65
  }
}
 
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Benjamin »

Version: 5.2.6-2ubuntu4.1

Yes, I copied the entire lib folder to projectName/lib/vendor/swift/. That line you gave me, gives me this:
stack trace
at ()
in SF_ROOT_DIR/lib/vendor/swift/classes/Swift/DependencyContainer.php line 103 ...
{

if (!$this->has($itemName))

{

throw new Swift_DependencyException(

'Cannot lookup dependency "' . $itemName . '" since it is not registered.'

);

}
at Swift_DependencyContainer->lookup('transport.smtp')
in SF_ROOT_DIR/apps/frontend/modules/content/actions/actions.class.php line 44 ...
at contentActions->executeCreate(object('sfWebRequest'))
in SF_SYMFONY_LIB_DIR/action/sfActions.class.php line 53 ...
at sfActions->execute(object('sfWebRequest'))
in SF_SYMFONY_LIB_DIR/filter/sfExecutionFilter.class.php line 90 ...
at sfExecutionFilter->executeAction(object('contentActions'))
in SF_SYMFONY_LIB_DIR/filter/sfExecutionFilter.class.php line 76 ...
at sfExecutionFilter->handleAction(object('sfFilterChain'), object('contentActions'))
in SF_SYMFONY_LIB_DIR/filter/sfExecutionFilter.class.php line 42 ...
at sfExecutionFilter->execute(object('sfFilterChain'))
in SF_SYMFONY_LIB_DIR/filter/sfFilterChain.class.php line 53 ...
at sfFilterChain->execute()
in SF_SYMFONY_LIB_DIR/filter/sfCommonFilter.class.php line 29 ...
at sfCommonFilter->execute(object('sfFilterChain'))
in SF_SYMFONY_LIB_DIR/filter/sfFilterChain.class.php line 53 ...
at sfFilterChain->execute()
in SF_SYMFONY_LIB_DIR/filter/sfCacheFilter.class.php line 65 ...
at sfCacheFilter->execute(object('sfFilterChain'))
in SF_SYMFONY_LIB_DIR/filter/sfFilterChain.class.php line 53 ...
at sfFilterChain->execute()
in SF_SYMFONY_LIB_DIR/filter/sfRenderingFilter.class.php line 33 ...
at sfRenderingFilter->execute(object('sfFilterChain'))
in SF_SYMFONY_LIB_DIR/filter/sfFilterChain.class.php line 53 ...
at sfFilterChain->execute()
in SF_SYMFONY_LIB_DIR/controller/sfController.class.php line 245 ...
at sfController->forward('content', 'create')
in SF_SYMFONY_LIB_DIR/controller/sfFrontWebController.class.php line 48 ...
at sfFrontWebController->dispatch()
in SF_SYMFONY_LIB_DIR/util/sfContext.class.php line 159 ...
at sfContext->dispatch()
in SF_ROOT_DIR/web/frontend_dev.php line 12 ...
Last edited by Benjamin on Thu Mar 12, 2009 4:21 pm, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Chris Corbyn »

Yes, Swift Mailer absolutely requires that you include the swift_required file since it doesn't only set up autoloading, it actually prepares dependency injection.

I think I'm going to refactor this so that people can use their own autoloader. Swift Mailer is doing this, which mean one of the already registered loaders is not valid:

1. Get the current list of autoloaders (callbacks)
2. Unregister all of those autoloaders
3. Register itself first on the autoloader stack
4. Re-register all of the current autoloaders

If I move my autoloader into it's own file, people will be able to set up their own autoloader to use swift without having to use mine (I'd prefer this too).
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Benjamin »

Ok. When I add print_r above line 65 I get the following output before the logic exception. What would you recommend that I do? Just comment out your autoloader?
Array
(
[0] => sfCoreAutoload
[1] => autoload
)
EDIT: Commenting out your autoloader code and just leaving in the spl_autoload_register('swift_autoload'); line appears to fix it.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Chris Corbyn »

Comment out the call to swift_autoload_register() in my swift_required.php file, but make sure you include that file.

In the next release I'll structure it this way:

You pick one of:

a) swift_autoloaded.php
b) swift_nonautoloaded.php

swift_required.php will be deprecated and will simply include the swift_autoloaded version. I'll probably think of better file names.

Basically, you use the nonautoloaded version Swift Mailer will assume you've configured your own autoloader to find classes in the "lib/classes" directory using Zend's naming conventions.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Chris Corbyn »

I'd just prevent that entire function from running personally. The only purpose that whole function serves is to set up autoloading.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Benjamin »

Maybe 3:

swift_zendRequire.php
swift_autoRequire.php
swift_noautoRequire.php
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Chris Corbyn »

Here's how I drafted it in Lighthouse: http://swiftmailer.lighthouseapp.com/pr ... utoloaders

Using my autoloader (no changes):

Code: Select all

require_once 'lib/swift_required.php';
Using your own autoloader:

Code: Select all

/* assumes you've configured an autoloader for swift */
 
require_once 'lib/swift_init.php';
The swift_required.php file just do those two things combined.

EDIT | This will be done today.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Chris Corbyn »

http://swiftmailer.org/downloads/get/Swift-4.0.2.tar.gz

No hacks needed. If you've got your own autoloader correctly configured now you can just include swift_init.php instead of swift_required.php.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Benjamin »

Fast response Chris :drunk: - Thanks a lot.
saiaman
Forum Newbie
Posts: 8
Joined: Mon Oct 06, 2008 10:03 am

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by saiaman »

Hi i've got the same problem but the fact is that i only have copied swift/ and swift.php inside my include path while i'm using Zend framework.

Do you have any idea ? or do i really need to add dependency_maps and other files in my include_path and require swift_init ???

Thank you
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Catchable fatal error: Argument 1 passed to Swift_Transport

Post by Chris Corbyn »

saiaman wrote:Hi i've got the same problem but the fact is that i only have copied swift/ and swift.php inside my include path while i'm using Zend framework.

Do you have any idea ? or do i really need to add dependency_maps and other files in my include_path and require swift_init ???

Thank you
You need the whole "lib/classes" path on your include_path. All the other files from the lib directory are needed too yes. Swift Mailer won't work without them. And swift_init.php must be included in all cases since it sets swift mailer up (it starts dependency injection).
Post Reply