/** * sends a email to the each of the mailTo. * * @param array $mailTo * @param string $subject * @param string $body * @param string $from * @return bool */ public function send(array $mailTo, $subject, $body, $from) { $message = $this->mailer->message(); $message->setBody($body); $message->setSubject($subject); $message->setFrom($from); $this->send_count = 0; foreach ($mailTo as $to) { $to = trim($to); if (!$to) { continue; } $message->setTo($to); if ($this->mailer->getSwiftMailer()->send($message)) { $this->send_count++; } } return true; }
/** * @test */ function default_sets_messages() { $default = MessageDefault::newInstance()->withFrom('*****@*****.**', 'from')->withReplyTo('*****@*****.**', 'reply')->withReturnPath('*****@*****.**'); /** @var DumbSpool $spool */ $mailer = Mailer::newInstance(Transport::forgeDumb($spool)); $mailer->setMessageDefault($default); $mailer->sendText('test mail', function ($message) { /** @var Swift_Message $message */ $message->setTo('*****@*****.**'); }); $msg = $spool->getMessage(); $this->assertEquals(['*****@*****.**' => ''], $msg->getTo()); $this->assertEquals(['*****@*****.**' => 'from'], $msg->getFrom()); $this->assertEquals(['*****@*****.**' => 'reply'], $msg->getReplyTo()); $this->assertEquals('*****@*****.**', $msg->getReturnPath()); }