使用单个附件发送批量电子邮件/使用Swiftmailer嵌入

I have the following functions that sends batch emails

public function sendAttendeeEmails(Swift_Plugins_DecoratorPlugin $decorator, int $per_emails = 5, int $pause = 5) : int
  {
      $this->mailer->registerPlugin($decorator)
      //   ->registerPlugin(new \Swift_Plugins_AntiFloodPlugin($pre_emails, $pause))
      //   ->registerPlugin(new \Swift_Plugins_ThrottlerPlugin(
      //     $per_emails, \Swift_Plugins_ThrottlerPlugin::MESSAGES_PER_MINUTE
      //   ))
      ;

      array_walk($this->getAttendees(), [ $this, 'sendEmail' ]);



      return empty($this->failed)? $this->sent : -1;
  }

In my "sendEmail" function

protected function sendEmail($recipient, $email) {
    $message = new Swift_Message();
    $
    $message->attach(
      Swift_Attachment::fromPath(
        ASSETS_FOLDER . "/{$recipient['code']}.pdf",
        'application/pdf'
        )->setFilename("{$recipient['code']}-attachment.pdf")
    );
    $this->message->setTo([ $email =>  $recipient['name']]);
    $this->sent = $this->mailer->send($this->message, $this->failed);

  }

Based on the documentation

Create a Transport from one of the provided Transports -- Swift_SmtpTransport, Swift_SendmailTransport, or one of the aggregate Transports. Create an instance of the Swift_Mailer class, using the Transport as it's constructor parameter. Create a Message. Iterate over the recipients and send message via the send() method on the Mailer object.

However, in executing the functions it appears that attachments and email addresses are being appended onto subsequent emails

My understanding that messages and email addresses would be sent uniquely

I need to send each individual a specific attachment without being aware of one another

php
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问