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