Tracking batchSend
Moderators: Chris Corbyn, General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Tracking batchSend
I'll post back here in a sec. This code is not correct if what you want is the Message-ID. It's also not correct for v4 (no $evt->getRecipients() method).
Something has just dawned on me however. If these recipients are all part of a batchSend() they will all have the same Message-ID (because they all get the same message). I think this should be considered a bug and the correct behaviour should be to regenerate the message ID after each send. I'll make this change today.
Something has just dawned on me however. If these recipients are all part of a batchSend() they will all have the same Message-ID (because they all get the same message). I think this should be considered a bug and the correct behaviour should be to regenerate the message ID after each send. I'll make this change today.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Tracking batchSend
Correct code:
But like I say, if these are all in one single call to batchSend() you'll find that all the IDs are the same. I can fix this so easily but you may have to wait a couple of hours for the next release.
Code: Select all
class Swift_Plugins_Return_id implements Swift_Events_SendListener {
private $messageIds=array();
public function returnId(Swift_Events_SendEvent $e) {
return $this->messageIds;
}
/**
* Not used.
*/
public function beforeSendPerformed(Swift_Events_SendEvent $evt)
{
}
public function sendPerformed(Swift_Events_SendEvent $evt)
{
$message = $evt->getMessage();
$this->messageIds[] = $message->getId();
}
}Re: Tracking batchSend
ok, just to add: I'm using send() and not batchsend() at the moment.
edit: I see that you already posted the code. Great, thanks, you're fast! I'll give it a try right away.
David
edit: I see that you already posted the code. Great, thanks, you're fast! I'll give it a try right away.
David
Re: Tracking batchSend
yup, message-id must be reset on each body / header change
Re: Tracking batchSend
Still no luck...
Right now I get this error again:
How should I pass the instance of Swift_events_SendEvent to Swift_Plugins_Return_id::returnId?
To recollect, this is the code I now use:
The plugin:
And the sending code:
Thanks again!
David
Right now I get this error again:
Code: Select all
Catchable fatal error: Argument 1 passed to Swift_Plugins_Return_id::returnId() must be an instance of Swift_Events_SendEvent, none given, called in /home/.../Swift-4.0.0-b4/examples/basics2.php on line 48 and defined in /home/.../Swift-4.0.0-b4/lib/classes/Swift/Plugins/ReturnIdPlugin.php on line 8To recollect, this is the code I now use:
The plugin:
Code: Select all
class Swift_Plugins_Return_id implements Swift_Events_SendListener {
//$this->messageIds=array();
private $messageIds = array();
public function returnId(Swift_Events_SendEvent $e) {
return $this->messageIds;
}
/**
* Not used.
*/
public function beforeSendPerformed(Swift_Events_SendEvent $evt)
{
}
public function sendPerformed(Swift_Events_SendEvent $evt) {
$message = $evt->getMessage();
$this->messageIds[] = $message->getId();
}
}Code: Select all
$mailer = Swift_Mailer::newInstance($transport);
//Create a message
$message = Swift_Message::newInstance('A basic message')
->setBody("the body
", 'text/plain')
->setTo(...)
->setFrom(...)
;
require "../lib/classes/Swift/Plugins/ReturnIdPlugin.php";
$mailer->registerPlugin($returnPlugin=new Swift_Plugins_Return_id());
//Send it
if ($mailer->send($message))
{
echo "Message sent!";
echo "\nId:" . $returnPlugin->returnId();
}
else
{
echo "Error sending";
}David
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Tracking batchSend
I just implemented itxdecock wrote:yup, message-id must be reset on each body / header change
Sorry, this method declaration:
Code: Select all
public function returnId(Swift_Events_SendEvent $e) {
//should be
public function returnId() {Re: Tracking batchSend
remove the bold section in the code :
returnId(Swift_Events_SendEvent $e) {
returnId(Swift_Events_SendEvent $e) {
Re: Tracking batchSend
Yup Safe routeChris Corbyn wrote:I just implemented itxdecock wrote:yup, message-id must be reset on each body / header changeAfter each send() inside any of the transports $message->generateId() is invoked. Seemed like the least expensive and most foolproof way to do it
![]()
Re: Tracking batchSend
Great, this works!!!!!!
Thank you both very much!
Cheers, David
Thank you both very much!
Cheers, David