Call to a member function setUsername (Swift)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
harleyflh75
Forum Newbie
Posts: 6
Joined: Wed Oct 31, 2007 1:33 pm

Call to a member function setUsername (Swift)

Post 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);
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Post 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.
harleyflh75
Forum Newbie
Posts: 6
Joined: Wed Oct 31, 2007 1:33 pm

Post 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);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I think you need to remove the "new Swift" parts of the line where $smtp is set.
harleyflh75
Forum Newbie
Posts: 6
Joined: Wed Oct 31, 2007 1:33 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
harleyflh75
Forum Newbie
Posts: 6
Joined: Wed Oct 31, 2007 1:33 pm

thanx

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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); 
harleyflh75
Forum Newbie
Posts: 6
Joined: Wed Oct 31, 2007 1:33 pm

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

are you still using the swift php4 code on the php5 server?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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. ;)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

of course.
admittingly, i skimmed the topic
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply