Example #1
0
 /**
  * Send a message.
  * @method send
  * @param  \vakata\mail\MailInterface $mail the message to be sent
  * @return array              array with two keys - 'good' and 'bad' - indicating successfull and failed addresses
  */
 public function send(MailInterface $mail)
 {
     $this->comm('MAIL FROM:<' . $mail->getFrom(true) . '>', [250]);
     $recp = array_merge($mail->getTo(true), $mail->getCc(true), $mail->getBcc(true));
     $badr = [];
     $good = [];
     foreach ($recp as $v) {
         try {
             $this->comm('RCPT TO:<' . $v . '>', [250, 251]);
             $good[] = $v;
         } catch (MailException $e) {
             $badr[] = $v;
         }
     }
     if (count($good)) {
         $this->comm('DATA', [354]);
         $data = (string) $mail;
         $data = explode("\n", str_replace(array("\r\n", "\r"), "\n", $data));
         foreach ($data as $line) {
             if (isset($line[0]) && $line[0] === '.') {
                 $line = '.' . $line;
             }
             $this->data($line . "\r\n");
         }
     }
     $this->comm('.', [250]);
     $this->comm('RSET', [250]);
     return ['good' => $good, 'fail' => $badr];
 }