Jyxo\Mail\Sender::sendBySmtp PHP Метод

sendBySmtp() приватный Метод

Sends an email using a SMTP server.
private sendBySmtp ( )
    private function sendBySmtp()
    {
        if (!class_exists(\Jyxo\Mail\Sender\Smtp::class)) {
            throw new Sender\Exception(sprintf('Could not sent the message. Required class %s is missing.', \Jyxo\Mail\Sender\Smtp::class));
        }
        try {
            $smtp = new Sender\Smtp($this->smtpHost, $this->smtpPort, $this->smtpHelo, $this->smtpTimeout);
            $smtp->connect();
            if (!empty($this->smtpUser)) {
                $smtp->auth($this->smtpUser, $this->smtpPsw);
            }
            // Sender
            $smtp->from($this->email->from->email);
            // Recipients
            $unknownRecipients = [];
            foreach (array_merge($this->email->to, $this->email->cc, $this->email->bcc) as $recipient) {
                try {
                    $smtp->recipient($recipient->email);
                } catch (\Jyxo\Mail\Sender\SmtpException $e) {
                    $unknownRecipients[] = $recipient->email;
                }
            }
            if (!empty($unknownRecipients)) {
                throw new Sender\RecipientUnknownException('Unknown email recipients.', 0, $unknownRecipients);
            }
            // Data
            $smtp->data($this->getHeader(), $this->createdBody);
            $smtp->disconnect();
        } catch (\Jyxo\Mail\Sender\RecipientUnknownException $e) {
            $smtp->disconnect();
            throw $e;
        } catch (\Jyxo\Mail\Sender\SmtpException $e) {
            $smtp->disconnect();
            throw new Sender\Exception('Cannot send email: ' . $e->getMessage());
        }
    }