BeforeSendListener plugin
Posted: Tue Jun 24, 2008 10:21 am
Hello
I (try to) use Swift to make a mailing application for my company. It's my first time in the world of mass mailing that's why I don't know if I'm going well ... So ...
I made something who send mails with "BatchSend" and all is ok. I retrieve all from my database (mails, users emails etc.). When each mail is sent I save some info in my database (to know wich mails as been send etc.). I made this with a BeforeSendListener plugin.
But I don't know how to pass the "database ID" of each mail receiver to my plugin, to save it. If I want to save the email it's ok because it's in the RecipientList, or the mail ID because it never change. But I don't know how to give this ID who change all the time to my plugin.
Now my code ....
My Swift code
My BeforeSendListener plugin
I tried to make my code clear, but I don't know if it's enough. My brain and my english are not so good now ...
If someone can help me to pass this ID .... Thank you !
I (try to) use Swift to make a mailing application for my company. It's my first time in the world of mass mailing that's why I don't know if I'm going well ... So ...
I made something who send mails with "BatchSend" and all is ok. I retrieve all from my database (mails, users emails etc.). When each mail is sent I save some info in my database (to know wich mails as been send etc.). I made this with a BeforeSendListener plugin.
But I don't know how to pass the "database ID" of each mail receiver to my plugin, to save it. If I want to save the email it's ok because it's in the RecipientList, or the mail ID because it never change. But I don't know how to give this ID who change all the time to my plugin.
Now my code ....
My Swift code
Code: Select all
//Before I import all files, class, data from database etc.
//SMTP connection
$swift =& new Swift(new Swift_Connection_SMTP('localhost'));
//Create message
$message = new Swift_Message(stripslashes($mail['Mail']['sujet']));
//Html message
$message->attach(new Swift_Message_Part($msgHtml, 'text/html'));
//Text message
$message->attach(new Swift_Message_Part($msgText));
//Load all users (id, email) who will receive the mail
$envoyerA = $this->query(....);
$recipients = new Swift_RecipientList();
//Loop through the result set and add onto the recipients list
foreach ($envoyerA as $personne) {
$recipients->addTo($personne['Membre']['email']);
//Here I want to pass the id of the user
//Like : $recipients->addId($personne['Membre']['id']); but okok it's impossible ...
}
//Anti-flood plugin.
$swift->attachPlugin(new Swift_Plugin_AntiFlood(90,10), 'anti-flood');
//BeforeSendListener plugin
$swift->attachPlugin(new AjoutBdd(), 'AjoutBdd');
//Give the mail id to the plugin
$swift->getPlugin("AjoutBdd")->setMailId($mail['Mail']['id']);
//Send mails
$batch =& new Swift_BatchMailer($swift);
$batch->send($message, $recipients, new Swift_Address($mail['Mail']['exp_mail'], $mail['Mail']['exp_nom']));
//Bye bye
$swift->disconnect();
Code: Select all
class AjoutBdd implements Swift_Events_SendListener {
protected $mail_id;
public function setMailId($mail_id) {
$this->mail_id = $mail_id;
}
public function getMailId() {
return $this->mail_id;
}
public function sendPerformed(Swift_Events_SendEvent $e) {
//Save data in the database
//And here I want to save the "Member Id" but I don't know how to pass it ...
sql = "INSERT INTO temp(id , member_id, mail_id, sent) VALUES('','$member_id','$this->mail_id','1')";
}
}
If someone can help me to pass this ID .... Thank you !