/** * send, Envoie le mail * * @param Message $message * @throws InvalidArgumentException * @throws MailException * @return bool */ public function send(Message $message) { if (empty($message->getTo()) || empty($message->getSubject()) || empty($message->getMessage())) { throw new InvalidArgumentException("Une erreur est survenu. L'expediteur ou le message ou l'object omit.", E_USER_ERROR); } if (isset($this->config['mail'])) { $section = $this->config['mail']['default']; if (!$message->fromIsDefined()) { $form = $this->config['mail'][$section]; $message->from($form["address"], $form["username"]); } else { if (!Str::isMail($message->getFrom())) { $form = $this->config['mail'][$message->getFrom()]; $message->from($form["address"], $form["username"]); } } } $to = ''; $message->setDefaultHeader(); foreach ($message->getTo() as $value) { if ($value[0] !== null) { $to .= $value[0] . ' <' . $value[1] . '>'; } else { $to .= '<' . $value[1] . '>'; } } $status = @mb_send_mail($to, $message->getSubject(), $message->getMessage(), $message->compileHeaders()); return (bool) $status; }
/** * Lance l'envoie de mail * * @param Message $message * @return bool */ public function send(Message $message) { $this->connection(); $error = true; // SMTP command if ($this->username !== null) { $this->write('MAIL FROM: <' . $this->username . '>', 250); } else { if ($message->getFrom() !== null) { $this->write('MAIL FROM: <' . $message->getFrom() . '>', 250); } } foreach ($message->getTo() as $value) { $to = ''; if ($value[0] !== null) { $to .= $value[0] . '<' . $value[1] . '>'; } else { $to .= '<' . $value[1] . '>'; } $this->write('RCPT TO: ' . $to, 250); } $this->write('DATA', 354); $data = 'Subject: ' . $message->getSubject() . Message::END; $data .= $message->compileHeaders(); $data .= 'Content-Type: ' . $message->getType() . '; charset=' . $message->getCharset() . Message::END; $data .= 'Content-Transfer-Encoding: 8bit' . Message::END; $data .= Message::END . $message->getMessage() . Message::END; $this->write($data); try { $this->write('.', 250); } catch (SmtpException $e) { echo $e->getMessage(); } $status = $this->disconnect(); if ($status == 221) { $error = false; } return (bool) $error; }