Force "by value" for swift message ?
Posted: Mon Oct 01, 2007 5:06 am
Hello !!
I Use swift to send emails who are compose like this :
- template with variables like this {test} (I use Decoration Plugin)
-There is attachments common to all the recipients
-some recipients have a specific attachments
So, I build my email (generic template + common attachments) and then I loop on all the recipients to attach specific files if necessary, I do this in a class method by giving the recipients ($destinataires), the swift message object ($message) and the sender ($from)
The problem is that when I call $current_message->attach() in the loop this modify the swift message object ITSEFL and not a COPY (this is logical because in PHP5 the arguments are pass by reference and not by value) ... but with this behavior the specific attachments are attached within the "original message (i.e. template + common attachments)
How can I attach specific attachments without modifying the "original message" ?? how can I send $message "by value" to my function so I have a COPY of the object and not a reference on this object ?
I've tried "clonning" in PHP5 without success :
But it doesnt work :
still modify the "original message" i.e. the message containing the template body + common attachments ..
Any ideas ? please
I Use swift to send emails who are compose like this :
- template with variables like this {test} (I use Decoration Plugin)
-There is attachments common to all the recipients
-some recipients have a specific attachments
So, I build my email (generic template + common attachments) and then I loop on all the recipients to attach specific files if necessary, I do this in a class method by giving the recipients ($destinataires), the swift message object ($message) and the sender ($from)
Code: Select all
private function doSendEmail($destinataires, $current_message, $from)
{
foreach ($destinataires as $destinataire)
{
// Specific attachements for the current recipient
foreach($destinataire->attachements as $attachement)
{
$current_message->attach(new Swift_Message_Attachment(base64_decode($attachement->data), $attachement->name, $attachement->mime));
}
//send message
$this->swift->send($current_message, $destinataire->email, $from);
}
}How can I attach specific attachments without modifying the "original message" ?? how can I send $message "by value" to my function so I have a COPY of the object and not a reference on this object ?
I've tried "clonning" in PHP5 without success :
Code: Select all
private function doSendEmail($destinataires, $message, $from)
{
$current_message = new Swift_Message();
$current_message = clone $message;
...
...
}Code: Select all
$current_message->attach(...)Any ideas ? please