SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot Tikila's Avatar
    Join Date
    Jun 2007
    Location
    Toronto
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SwiftMail is killing me with Catchable fatal error:Argument 1 passed to Swift::__cons

    Am having a hard time getting SwiftMailer to work.
    It never passes the connection phase.port25 is open(called my isp),my host opened both port 25 and 26,tested smtp with phpMailer and worked fine.
    I tried all connections possible,all failed-sendmail,native,multi,etc.
    So i think,there is something wrong with the script
    I downloaded the zip package(Swift-3.3.2-php5.zip ) as i use php.5
    I copied the author code located here:
    http://www.swiftmailer.org/source/
    and pasted it over the one i downloaded,still same problem
    PHP Code:
    <?php
    require_once "lib/Swift.php";
    require_once 
    "lib/Swift/Connection/SMTP.php";
    $swift =& new Swift(new Swift_Connection_SMTP ("MyDomain.com",25));// or ("mail.MyDomain,25") or ("mail.MyDomain,26")
    $swift =& new Swift($smtp);
    $message =& new Swift_Message ("SwiftMail Test Message" );
    $message->setContentType("text/html");
    if (
    $swift->send($message,"Me@MyEmailProvide.com","Admin@MyDomain.com")){

    echo 
    "Message sent";
    }
    else{

    echo 
    "Message failed to send";
    }
    $swift->disconnect(); 
    ?>
    As you see,I have skipped many features to minimize errors
    For example when i use:

    PHP Code:
    $smtp->setTimeout(2); 
    it throws the following error to my face:

    PHP Code:
    Fatal errorCall to a member function setTimeout() on a non-object in /home/MyAcount/public_html/Test.php on (whatever line 
    it is located

    When i use:

    PHP Code:
    $smtp->setUsername("MyUsername"); 
    $smtp->setPassword("MyPassword"); 
    am yelled at with:

    PHP Code:
    Fatal errorCall to a member function setUsername() on a non-object in /home/MyAcount/public_html/Test.php on line 4 

    Now I could not pass this error that is killing me:

    PHP Code:
    Catchable fatal errorArgument 1 passed to Swift::__construct() must implement interface Swift_Connectionnull givencalled in /home/MyAcount/public_html/Test.php on line 5 and defined in /home/MyAcount/public_html/lib/Test.php on line 81 

    Here is what i have in line 5:

    PHP Code:
    $swift =& new Swift($smtp); 
    and here what i have in lin 81(it must be somewhere between here)

    PHP Code:
      public function __construct(Swift_Connection $conn$domain=false$options=null)
      {
        
    $this->initializeEventListenerContainer();
        
    $this->setOptions($options);
        
        
    $log Swift_LogContainer::getLog();
        
        if (
    $this->hasOption(self::ENABLE_LOGGING) && !$log->isEnabled())
        {
          
    $log->setLogLevel(Swift_Log::LOG_NETWORK);
        }

        if (!
    $domain$domain = !empty($_SERVER["SERVER_ADDR"]) ? "[" $_SERVER["SERVER_ADDR"] . "]" "localhost.localdomain";
        
        
    $this->setDomain($domain);
        
    $this->connection $conn;
        
        if (
    $conn && !$this->hasOption(self::NO_START))
        {
          if (
    $log->hasLevel(Swift_Log::LOG_EVERYTHING)) $log->add("Trying to connect..."Swift_Log::NORMAL);
          
    $this->connect();
        }
      } 
    If you had similar problems with SwiftMail and got it working,I would be grateful if you can help out.

    Thank you all in advance!

  2. #2
    SitePoint Evangelist catweasel's Avatar
    Join Date
    Apr 2007
    Location
    Goldfields, VIC, Australia
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the purpose of this line -
    PHP Code:
    $swift =& new Swift($smtp); 
    It appears to render the line before it redundant.

    also.. as of php5 you don't need =& .. objects are returned by reference automatically.

  3. #3
    SitePoint Zealot Tikila's Avatar
    Join Date
    Jun 2007
    Location
    Toronto
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by catweasel View Post
    What is the purpose of this line -
    PHP Code:
    $swift =& new Swift($smtp); 
    It appears to render the line before it redundant.

    also.. as of php5 you don't need =& .. objects are returned by reference automatically.
    thanks catweasel
    yes,it is redundant.I removed it.Now when i proceeded,I got this:
    PHP Code:
    Fatal errorUncaught exception 'Swift_BadResponseException' with message 'Expected response code(s) [250] but got response [554 5.7.7 Forged HELO .]' in /home/MyAccount/public_html/lib/Swift.php:250 Stack trace#0 /home/MyAccount/public_html/lib/Swift.php(310): Swift->assertCorrectResponse(Object(Swift_Events_ResponseEvent), 250) #1 /home/MyAccount/public_html/lib/Swift.php(373): Swift->command('MAIL FROM: <Admin...', 250) #2 /home/MyAccount/public_html/test.php(8): Swift->send(Object(Swift_Message), 'Me@MyEmailProvide.c...', 'Admin@MyDom...') #3 {main} thrown in /home/MyAccount/public_html/lib/Swift.php on line 250 

  4. #4
    SitePoint Evangelist catweasel's Avatar
    Join Date
    Apr 2007
    Location
    Goldfields, VIC, Australia
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well now it's working but the transaction failed.. The server thinks you are forging your identity.. possibly because you have 'mydomain.com' as your domain.

    info on smtp response codes

    and info related to your particular response error (forged HELO)

    You can get your app to fail gracefully with these errors by using a try-catch block and catch the errors before it spews out onto the screen.

  5. #5
    SitePoint Zealot Tikila's Avatar
    Join Date
    Jun 2007
    Location
    Toronto
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by catweasel View Post
    well now it's working but the transaction failed.. The server thinks you are forging your identity.. possibly because you have 'mydomain.com' as your domain.

    info on smtp response codes

    and info related to your particular response error (forged HELO)

    You can get your app to fail gracefully with these errors by using a try-catch block and catch the errors before it spews out onto the screen.
    Thanks catweasel,you are right
    I tought of the forcing same way hotmail rejects mail,I add an Reply to sorta of thing and got rid of the error;
    PHP Code:
     $message->setReturnPath("Admin@mydomain.com"); 
    But now i got this error:
    PHP Code:
    Fatal errorUncaught exception 'Swift_BadResponseException' with message 'Expected response code(s) [250] but got response [530 5.7.0 Authentication required]' in .. 
    So when I added the authentication code,I got the above error:
    PHP Code:
    $smtp->setUsername("MyUsername"); 
    $smtp->setPassword("MyPassword"); 
    PHP Code:
    Fatal errorCall to a member function setUsername() on a non-object in /home/MyAccount/public_html/test.php 
    same dilemma cycle.

  6. #6
    SitePoint Evangelist catweasel's Avatar
    Join Date
    Apr 2007
    Location
    Goldfields, VIC, Australia
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    isn't it supposed to be -
    $swift->setUsername('Blah');

    not -
    $smtp->setUsername('blah');


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •