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条回答

    报告相同问题?

    悬赏问题

    • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效