Page 1 of 1

php4 chokes when compiling swift.php (looks like php5 code)

Posted: Fri Apr 20, 2007 11:15 am
by billgoodyear
I have a php4 install (4.9) and im having the following error when im using swiftmailer

[client 192.168.245.1] PHP Fatal error: Call to a member function on a non-object in /var/www/phpincludes/classes/swiftmailer/lib/Swift.php on line 404, referer: http://test.deepercontrol.com/controlce ... update.php

Line 404 of the Swift.php is the following:

$log_active = $this->log->isEnabled();

This looks to me to be php5 code.

I tried installing the PHP4 editions 3.1.2 and 3.1.3 and its in both (the tar.gz for 3.1.3 and the .zip for 3.1.2)

Is there a problem with the archives. Can someone point me to a php4 version?

Thanks

Posted: Fri Apr 20, 2007 11:31 am
by John Cartwright
Without seeing your code, theres little we can do.

Posted: Fri Apr 20, 2007 11:41 am
by billgoodyear
Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Here is my code:

Code: Select all

function sendmail($parms) {
	$swift =& new Swift();

	$smtp =& new Swift_Connection_SMTP("mailserver", 26);
	$smtp->setUsername("noreply");
	$smtp->setPassword("XXXXXXXXX"); 

	$recipients =& new Swift_RecipientList();
	$recipients->addTo($parms["email_address"]);

	$message =& new Swift_Message($parms["subject"], $parms["message"], "text/html");
 
	if (! $swift->batchsend($message, $recipients, new Swift_Address("newsletter@deepercalling.com", "deeperNews"))) {
		die("Message failed to send");
	}
}
Im using php 4.3.9 (not 4.9 as i stated above :-)

This is cobbled together from the examples on the swiftmailer website. I know im using port 26 for SMTP even though its unusual. mailserver is setup in the hosts file to resolve to the correct IP address. Ive set this one up to do a recipientlist of 1, even though normally ill be batching this up into blocks of probably 100 or so mails to deliver to an email list of about 40,000 customers.

Im using Apache James with a Mysql backend. Id sure love it if i could just insert the mail messages directly into James Mysql database and bypass SMTP - maybe a good class to work on with Swiftmailer!!

Thanks in advance for your help.


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Apr 20, 2007 12:17 pm
by John Cartwright
Hint: your not doing anything with $smtp

Take a look at http://swiftmailer.org/wikidocs/v3/tutorials/basic

Posted: Fri Apr 20, 2007 12:40 pm
by billgoodyear
Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


ok, caught that!

Here is what i have now

Code: Select all

$smtp =& new Swift_Connection_SMTP("database", 26);
				$smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
				$smtp->setUsername("noreply");
				$smtp->setPassword("XXXXXXXXX"); 
				$swift =& new Swift($smtp);

				$recipients =& new Swift_RecipientList();
				$recipients->addTo($parms["email_address"]);

				$message =& new Swift_Message($parms["subject"], $parms["message"], "text/html");
 
				$swift->send($message, $parms["email_address"], "newsletter@deepercalling.com");
And im getting this error:

Code: Select all

[client 68.209.0.218] PHP Fatal error:  <br /><strong>Uncaught Error</strong> of type [swift_connection_exception] with message [Authentication is not supported by the server but a username and password was given.]<br /> 
@0 dc_smarty::dc_print() in /xfsdata/www/htdocs_deepercontrol/controlcenter/content/index_content_update.php on line 414<br /> 
@1 dc_smarty::display() in /xfsdata/www/phpincludes/classes/smarty/dc_smarty.php on line 43<br /> 
@2 dc_smarty::fetch() in /xfsdata/www/phpincludes/smarty/libs/Smarty.class.php on line 1101<br /> 
@3 smarty_core_process_cached_inserts() in /xfsdata/www/phpincludes/smarty/libs/Smarty.class.php on line 1176<br /> 
@4 insert_getmaincontent() in /xfsdata/www/phpincludes/smarty/libs/internals/core.process_cached_inserts.php on line 49<br /> 
@5 emailmanager::sendtestglobalcampaign() in /xfsdata/www/htdocs_deepercontrol/controlcenter/content/index_content_update.php on line 178<br /> 
@6 emailmanager::sendemail() in /xfsdata/www/phpincludes/classes/email/emailManager.php on line 211<br /><br /> in /xfsdata/www/phpincludes/classes/swiftmailer/Swift-3.1.3-php4/lib/Swift/Errors.php on line 99, referer: http://www.deepercontrol.com/controlcenter/content/index_content_update.php
Does this mean that resolving to hostname "database" on port 26 is not working?


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Apr 20, 2007 12:44 pm
by billgoodyear
Also, a telnet to "database" on port 26 from the machine works as shown below:

# telnet database 26

Trying 66.XXXXXXXX...
Connected to database (66.XXXXXXXX).
Escape character is '^]'.
220 titan.deepercalling.com SMTP Server (JAMES SMTP Server 2.3.0) ready Fri, 20 Apr 2007 13:43:21 -0400 (EDT)
HELO deepercalling.com
250 XXXXX.deepercalling.com Hello deepercalling.com (adsl-068-209-000-218.sip.asm.bellsouth.net [68.209.0.218])
QUIT

Posted: Fri Apr 20, 2007 1:25 pm
by Weirdan
Hint (straight from the stack trace):
Authentication is not supported by the server but a username and password was given.

Posted: Fri Apr 20, 2007 3:02 pm
by Chris Corbyn
I know; I put these stack traces in for a reason but I think it's probably lead to more requests for help.

Are you sure the SMTP server needs a password? When you telnet, type EHLO, not HELO and if you see the word "AUTH" in there then it will support authentication (but not strictly require it). If it doesn't say "AUTH" then the server doesn't use authentication.

In relation the the first post, I'm guessing you have error reporting turned off since you should have gotten a bad parameter error from PHP itself.

Why does it look like PHP5 code? :? $this->log->enable(). That's perfectly valid PHP4. $this->getLog()->enable() wouldn't be valid in PHP4 however.

EDIT | Actually, the response from your server does not say it's ESMTP, it says it's just basic SMTP. It will not support authentication.

Posted: Mon Apr 23, 2007 11:54 am
by billgoodyear
Hi,

I changed my configuration of the Apache James email server to disclose authentication. For some reason by default it does not.

Now when you do EHLO i get the following:

220 titan.deepercalling.com SMTP Server (JAMES SMTP Server 2.3.0) ready Mon, 23
Apr 2007 12:51:58 -0400 (EDT)
EHLO deepercompany.com
250-titan.deepercalling.com Hello deepercompany.com (adsl-068-209-000-218.sip.as
m.bellsouth.net [68.209.0.218])
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-PIPELINING
250 ENHANCEDSTATUSCODES

One thing to note though is that swiftmailer still dies as follows - it looks like it things my JAMES email server does not support Authentication. Have i done something wrong? The error from Swiftmailer is below

PHP Fatal error: <br /><strong>Uncaught Error</strong> of type [swift_connection_exception] with message [Authentication is not supported by the server but a username and password was given.]<br /> @0 emailmanager::queueprocess() in /xfsdata/www/htdocs_deepercontrol/batchcenter/hourly/batchmail.php on line 26<br /> @1 emailmanager::sendemail() in /xfsdata/www/phpincludes/classes/email/emailManager.php on line 359<br /> @2 swift::swift() in /xfsdata/www/phpincludes/classes/email/emailManager.php on line 501<br /> @3 swift::connect() in /xfsdata/www/phpincludes/classes/swiftmailer/Swift-3.1.3-php4/lib/Swift.php on line 109<br /><br /> in /xfsdata/www/phpincludes/classes/swiftmailer/Swift-3.1.3-php4/lib/Swift/Errors.php on line 99


Lastly, my ignorance on the X->Y->Z() , i thought that was PHP5, did not understand that you couild do that in version 4.

Posted: Mon Apr 23, 2007 12:37 pm
by Chris Corbyn
That server is not following standards. If it supports ESMTP is MUST says ESMTP in the 220 greeting. Yours doesn't :?

I wrote a class to fix this for someone else before, let me find it :)

Posted: Mon Apr 23, 2007 12:41 pm
by Chris Corbyn
viewtopic.php?t=65735

I'd suggest using a different mail server if you can. I'm surprised something from apache would have this problem. If I see one more server doing tis I'll have to patch something into the core to force ESMTP. The problem is, it would be illegal to say EHLO to a server that doesn't support ESMTP. You'd get a bad command response.

EDIT | You're using PHP4 so you'll have to use this converted version instead.

Code: Select all

<?php 

require_once "lib/Swift.php"; 
Swift_ClassLoader::load("Swift_Connection_SMTP"); 

//Make a custom plugin just to hack at the responses and commands 
class SayESMTP extends Swift_Events_Listener { 
  function responseReceived(&$e) { 
    if ($e->getCode() == 220) { 
      $e->setString("220 ESMTP whatever"); 
      $swift =& $e->getSwift(); 
      $swift->connection->setExtension("AUTH", array("LOGIN")); 
    } 
  } 
} 

$smtp =& new Swift_Connection_SMTP("server.tld"); 
$smtp->setUsername("user"); 
$smtp->setPassword("pass"); 

//Force swift to wait for us to load a plugin 
$swift =& new Swift($smtp, null, SWIFT_NO_START); 
$swift->attachPlugin(new SayESMTP(), "hack"); 

//Now connect 
$swift->connect(); 

//and continue as usual 

$swift->send( .... );

Posted: Mon Apr 23, 2007 12:42 pm
by billgoodyear
Ok, got it. I see the issue and i was working on it from another angle.

I changed the SMTP class and added the following (search for true == true). Its a bad fix but it gets me over the immediate problem.

foreach ($this->authenticators as $name => $obj)
{
//Server supports this authentication mechanism
if (($this->hasExtension("AUTH") && in_array($name, $this->getAttributes("AUTH"))) || $name{0} == "*" || true == true)
{
$tried++;
if ($this->authenticators[$name]->isAuthenticated($user, $pass, $swift)) return true;
}
}


Secondly the PLAIN login was failing authentication. I looked into another post and was able to update PLAIN.php and add in the base64_encode and that solved the problem. I did not need to change the parameters that were being passed, only needed to base64 encode them. So if anyone is using Apache James with the built in PLAIN authentication, these two fixes will get you up and running.

I realize these are temporary fixes so i'll try to improve the code and submit it back. Perhaps the true == true can be replaced with some test based on a configuration variable?

Posted: Mon Apr 23, 2007 12:45 pm
by Chris Corbyn
3.1.4 fixes PLAIN authentication. You can safely replace your version with it.

Posted: Mon Apr 23, 2007 12:58 pm
by billgoodyear
Thanks for all your assistance. I'll move the patches into place tomorrow and see how it goes.

Im using Apache James as its about the only system i could find that would allow me to add in user extensions to customize how mail is handled. It also has the option of using a mysql database as a backend, which we do.

We can run easy SQL commands to find out how many messages are in the queue, what the receipients are, and even query the deadletter queue for undeliverable email messages. For someone more comfortable with PHP and programming than with configuring SENDMAIL - its much better.

BTW, just want to say thanks to you and the community here. I was able to work through all our issues very quickly and the product is working great now. We're about to start our campaigns which go out to about 40,000 email addresses, so i'll keep you posted on how the solution goes.