Page 1 of 1

Call to a member function setUsername (Swift)

Posted: Wed Oct 31, 2007 1:41 pm
by harleyflh75
We have recently ported to php5 on a new server but keep getting this error that we didn't get with the old server

Fatal error: Call to a member function setUsername() on a non-object in /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/contact.php on line 204

any ideas

Code: Select all

//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";

//Connect to SMTP (PHP5)
$swift = new Swift(new Swift_Connection_SMTP("mail.dixiechopper2008.com", 25));
$smtp->setUsername("admin@dixiechopper2008.com");
$smtp->setpassword("overtime");
 
//$smtp =& new Swift_Connection_SMTP("some-host.tld", 25);
$swift =& new Swift($smtp);
$swift2 =& new Swift($smtp);

Posted: Wed Oct 31, 2007 1:53 pm
by aliasxneo
It means $smtp is not set or was never initialized as an object.

I don't see anywhere in the code where $smtp is initialized so it's most likely a problem in lib/Swift/Connection/SMTP.php.

Posted: Wed Oct 31, 2007 2:08 pm
by harleyflh75
should it be this way instead

Code: Select all

//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";

//Connect to SMTP (PHP5)
$smtp = new Swift(new Swift_Connection_SMTP("mail.dixiechopper2008.com", 25));
$smtp->setUsername("admin@dixiechopper2008.com");
$smtp->setpassword("overtime");
 

$swift = new Swift($smtp);
$swift2 = new Swift($smtp);

Posted: Wed Oct 31, 2007 2:15 pm
by feyd
I think you need to remove the "new Swift" parts of the line where $smtp is set.

Posted: Wed Oct 31, 2007 2:20 pm
by harleyflh75
tried it and got this message...in the docs to use php5 the new Swift is needed thought


Fatal error: Uncaught exception 'Swift_ConnectionException' with message 'Authentication failed using username 'admin@dixiechopper2008.com' and password '********'' in /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/lib/Swift/Connection/SMTP.php:414 Stack trace: #0 /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/lib/Swift/Connection/SMTP.php(331): Swift_Connection_SMTP->runAuthenticators('admin@dixiechop...', 'overtime', Object(Swift)) #1 /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/lib/Swift.php(264): Swift_Connection_SMTP->postConnect(Object(Swift)) #2 /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/lib/Swift.php(220): Swift->handshake(Object(Swift_Events_ResponseEvent)) #3 /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/lib/Swift.php(101): Swift->connect() #4 /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/contact.php(208): Swift->__construct(Object(Swift_Connection_SMTP)) #5 {main} thrown in /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/lib/Swift/Connection/SMTP.php on line 414

Posted: Wed Oct 31, 2007 2:23 pm
by feyd
The Swift class doesn't have the methods to set authentication information. Even the documentation supports this: http://swiftmailer.org/wikidocs/v3/conn ... entication

thanx

Posted: Wed Oct 31, 2007 2:38 pm
by harleyflh75
First of all thanx for your replies and help


this is what we had on the old server running php4:

Code: Select all

//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";

//Connect to Server (PHP4)
$smtp =& new Swift_Connection_SMTP("smtp.dixiechopper2008.com", SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_TLS);
$smtp->setUsername("xxxxxxx");
$smtp->setpassword("xxxxxxx");

$swift =& new Swift($smtp);
$swift2 =& new Swift($smtp);

the new server is running php5 and the smtp server is changed to mail.dixiechopper2008.com
I tried different code combinations that was in the documentation could you tell me what the proper code should be?

Code: Select all

//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";

//Connect to SMTP (PHP5)
$smtp = new Swift(new Swift_Connection_SMTP("mail.dixiechopper2008.com", 25));
$smtp->setUsername("admin@dixiechopper2008.com");
$smtp->setpassword("overtime");
 

$swift = new Swift($smtp);
$swift2 = new Swift($smtp);

again thanx for your help

Posted: Wed Oct 31, 2007 3:14 pm
by Zoxive
Did you read any of the posts? Feyd suggested you remove the 1st call of New Swift, which is correct.

He even posted a link later showing exactly the code you should be using.

Code: Select all

$smtp = new Swift(new Swift_Connection_SMTP("mail.dixiechopper2008.com", 25)); 
->

Code: Select all

$smtp = new Swift_Connection_SMTP("mail.dixiechopper2008.com", 25); 

Posted: Wed Oct 31, 2007 3:26 pm
by harleyflh75
and i have done that i used this code

Code: Select all

//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";

//Connect to SMTP (PHP5)
$smtp = new Swift_Connection_SMTP("mail.dixiechopper2008.com", 25);
$smtp->setUsername("admin@dixiechopper2008.com");
$smtp->setpassword("overtime");


$swift = new Swift($smtp);
$swift2 = new Swift($smtp);
and i got this error as i stated

Fatal error: Uncaught exception 'Swift_ConnectionException' with message 'Authentication failed using username 'admin@dixiechopper2008.com' and password '********'' in /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/lib/Swift/Connection/SMTP.php:414 Stack trace: #0 /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/lib/Swift/Connection/SMTP.php(331): Swift_Connection_SMTP->runAuthenticators('admin@dixiechop...', 'overtime', Object(Swift)) #1 /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/lib/Swift.php(264): Swift_Connection_SMTP->postConnect(Object(Swift)) #2 /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/lib/Swift.php(220): Swift->handshake(Object(Swift_Events_ResponseEvent)) #3 /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/lib/Swift.php(101): Swift->connect() #4 /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/contact.php(208): Swift->__construct(Object(Swift_Connection_SMTP)) #5 {main} thrown in /usr/local/www/vhosts/dixiechopper2008.com/httpdocs/lib/Swift/Connection/SMTP.php on line 414

Posted: Wed Oct 31, 2007 4:01 pm
by s.dot
are you still using the swift php4 code on the php5 server?

Posted: Thu Nov 01, 2007 10:39 am
by feyd
scottayy wrote:are you still using the swift php4 code on the php5 server?
The "uncaught exception" and __construct() referenced in the error would suggest PHP 5 code. ;)

Posted: Thu Nov 01, 2007 11:08 am
by s.dot
of course.
admittingly, i skimmed the topic