Search code examples
phpswiftmailermailer

Using swift mailer to send personalize email


If i use SWIFT MAILER to send a thousand email:

Not personilzed case:

$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
  ->setBody('Here is the message itself')

It can send with one array.

However, when i have to send personalize letter

FOREACH ($name as $receiver){
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array($receiver))
  ->setBody('Here is the message itself')}

Since the content is different , I have to use foreach to send one mail per once time??Is that more efficient way? I just have to specific the receiver name and the unsubscribe id in each mail sent.

Thank you for help


Solution

  • The Decorator plugin was created for just this purpose.