Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Envoye de mail simulaire a la fonction mail de PHP
  *
  * @param string $to Le destinateur
  * @param string $subject L'objet du mail
  * @param string $data Le message du meail
  * @param array  $headers [optinal] Les entĂȘtes additionnel du mail.
  * @return SimpleMail|Smtp
  */
 public static function raw($to, $subject, $data, array $headers = [])
 {
     $message = new Message();
     $message->to($to)->subject($subject)->setMessage($data);
     foreach ($headers as $key => $value) {
         $message->addHeader($key, $value);
     }
     return static::$instance->send($message);
 }
Example #3
0
 /**
  * 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;
 }