Posted: Fri Jun 02, 2006 4:23 pm
woohoo, i found a bug.
Cheerz chris, appreciate it
Cheerz chris, appreciate it
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
This is perectly normal. If sendmail (or exim or any other MTA) is daemonised it will keep trying the queue every 15 mins or so. If messages can't be delivered, the system will keep trying for around 72 hours before giving up. If something fatal happened the messages may be frozen and abandoned altogether. You can retry all the messages pretty quickly by running the following if memory serves correctly:scottayy wrote:I just have a question about sendmails mail spool. Oft times i check the mail spool and there's ~1000 messages in it. Bad email addresses? System overload?
It tries straight away. If there's a problem, or it's busy doing something else at the time then it goes on the queue.scottayy wrote:What happens when a new email needs to be sent and there's messages in the mail queue? Does it go to the bottom of the list or does it try right away?
Hey thanks! Glad you like itscottayy wrote:Edit: Thank you for this Chris, it is spectacular. I was (still am, till i put your class to use) having some great difficulty getting activation emails to send. Pretty important part! I've tested your class with yahoo, gmail, hotmail, amd various POP3 accounts. Works perfect! =] I actually tried phpmailer BEFORE i tried this class, simply because it was more tested and widely used. Mistake. PHPMailer was a bit confusing and complained that I don't have server relaying enabled? I didn't know what that meant, so I went with Swifty. It works pretty... swiftlyStraight and to the point.
You should register on SF and FM if not already. Get more exposure and catch any issues quicker. Excellent library by the way - reading the code was actually pleasant. If the good reviews continue I'll start using it in my newer projects.Page hit 1,345 times since 27th May 2006 (619 unique).
It's on HotScripts (Google "Swift Mailer"). I've applied for SF too - still awaiting a response but since I regsitered it I've switched from GPL to LGPL.Maugrim_The_Reaper wrote:You should register on SF and FM if not already. Get more exposure and catch any issues quicker. Excellent library by the way - reading the code was actually pleasant. If the good reviews continue I'll start using it in my newer projects.Page hit 1,345 times since 27th May 2006 (619 unique).
Code: Select all
<?php
/**
* Anti-Flood plugin for Swift Mailer, a PHP Mailer class.
*
* @package Swift
* @version >= 1.1.2
* @author Chris Corbyn
* @date 4th June 2006
* @license http://www.gnu.org/licenses/lgpl.txt Lesser GNU Public License
*
* @copyright Copyright © 2006 Chris Corbyn - All Rights Reserved.
* @filesource
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to
*
* The Free Software Foundation, Inc.,
* 51 Franklin Street,
* Fifth Floor,
* Boston,
* MA 02110-1301 USA
*
* "Chris Corbyn" <chris@w3style.co.uk>
*
*/
class Swift_Anti_Flood_Plugin implements Swift_IPlugin
{
/**
* Name of the plugin (identifier)
* @var string plugin id
*/
public $pluginName = 'Anti_Flood';
/**
* The maximum number of messages to send
* over a single connection
* @var int max messages
*/
public $maxMessages;
/**
* Current messages sent since last reconnect
* or plugin loading.
* @var int current messages
*/
private $currMessages = 0;
/**
* Contains a reference to the main swift object.
* @var object swiftInstance
*/
private $swiftInstance;
/**
* Constructor.
* @param int max messages, optional
* @return void
*/
public function __construct($max=10)
{
$this->maxMessages = (int) $max;
}
/**
* Load in Swift
* @param object SwiftInstance
*/
public function loadBaseObject(&$object)
{
$this->swiftInstance =& $object;
}
/**
* Event handler for onSend.
*/
public function onSend()
{
$this->currMessages++;
if ($this->currMessages >= $this->maxMessages)
{
$this->reconnect();
$this->currMessages = 0;
}
}
/**
* Reconnect to the server
*/
private function reconnect()
{
$this->swiftInstance->close();
$this->swiftInstance->connect();
//Re-authenticate if needs be
if (!empty($this->swiftInstance->username))
{
$this->swiftInstance->authenticate(
$this->swiftInstance->username,
$this->swiftInstance->password
);
}
}
}
?>Code: Select all
$swift = new Swift($connectionObject);
$swift->loadPlugin(new Swift_Anti_Flood_Plugin(10)); //The 10 is default in any case
/* Go ahead and send out batch mail as usual */Error running command: MAIL FROM: . No connection available near Swift::send in /home/d11wtq/public_html/Swift-1.1.4/test.php on line 22
Sending failed on command: MAIL FROM: near Swift::send in /home/d11wtq/public_html/Swift-1.1.4/test.php on line 22
Code: Select all
<?php
/**
* Error handling plugin for Swift Mailer, a PHP Mailer class.
*
* @package Swift
* @version >= 0.0.4
* @author Chris Corbyn
* @date 8th June 2006
* @license http://www.gnu.org/licenses/lgpl.txt Lesser GNU Public License
*
* @copyright Copyright © 2006 Chris Corbyn - All Rights Reserved.
* @filesource
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to
*
* The Free Software Foundation, Inc.,
* 51 Franklin Street,
* Fifth Floor,
* Boston,
* MA 02110-1301 USA
*
* "Chris Corbyn" <chris@w3style.co.uk>
*
*/
class Swift_Errors_Plugin implements Swift_IPlugin
{
/**
* Name of the plugin (identifier)
* @var string plugin id
*/
public $pluginName = 'Errors';
/**
* Contains a reference to the main swift object.
* @var object swiftInstance
*/
private $swiftInstance;
/**
* The norm is the echo and continue.
* Settting this to TRUE makes it echo the die()
* @var bool halt
*/
private $halt;
/**
* Constructor.
* @param bool halt (if the script should die() on error)
*/
public function __construct($halt=false)
{
$this->halt = (bool) $halt;
}
/**
* Load in Swift
* @param object SwiftInstance
*/
public function loadBaseObject(&$object)
{
$this->swiftInstance =& $object;
}
/**
* Event handler for onError
*/
public function onError()
{
$this_error = $this->swiftInstance->lastError;
$error_info = $this->getErrorStartPoint();
if (!empty($error_info['class'])) $class = $error_info['class'].'::';
else $class = '';
$file_info = ' near '.$class.$error_info['function'].
' in <strong>'.$error_info['file'].'</strong> on line <strong>'.
$error_info['line'].'</strong><br />';
$output = '<br />'.$this_error.$file_info;
echo $output;
if ($this->halt) exit();
}
/**
* Get the command that caused the error
*/
private function getErrorStartPoint()
{
$trace = debug_backtrace();
$start = array_pop($trace);
return array(
'file' => $start['file'],
'line' => $start['line'],
'class' => $start['class'],
'function' => $start['function']
);
}
}
?>Seems you could call your own error handling function with set_error_handler()d11wtq wrote:I want to generate my own user level warning without that info in it.
But isn't that for actual PHP errors? These are my own defined errors.... they're not actual PHP errors if you know what I meanscottayy wrote:Seems you could call your own error handling function with set_error_handler()d11wtq wrote:I want to generate my own user level warning without that info in it.
Agreed, but that's what swift already does. It logs them in an array "errors" and stores the latest in "lastError". Nothing ever gets displayed on page, that's what hasFailed() and isConnected() were for. The problem is that I'm getting a fair few emails from n00b people who just haven't checked if things worked or not (it's pretty much always realying denied issues) so I thought I'd make this to make it clear as mud. If I make it too complicated nobody but really experienced developers will choose to use Swiftarborint wrote:Rather than echoing, why don't you make this class an error logger. Instead of echoing, save the messages in an array. Then the app can do whatever it wants to with them -- display, write to a file, etc. Just add a getErrors() and showErrors() methods.
It shouldn't do that. close() just fclose()'s the connection which is implied (apart from sending a QUIT command) at the end of script execution in any case. Can you send an example of where you're seeing this cheers?akreider wrote:I'd like to warn people to be sure to close the mailer ($mailer->close).
Otherwise it hangs and you don't know why... I just thought my host had banned me from using sendmail.
Aaron