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) {
            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;
    }
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) {
            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;
    }
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 ) { 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 ; }
Start sending mail

@param  Message $message
@return bool
@throws SocketException
@throws ErrorException
Start sending mail