drqj8605 2018-09-30 23:59
浏览 28

使用单个附件发送批量电子邮件/使用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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!