Use SMTP stream to send mail
@param array $smtp SMTP parameter array
server, port, domain, username, password
@return void
547302
public function setSMTPStream ($smtp = FALSE)
    {

        // If an SMTP parameter array has been passed

        if (is_array ($smtp))
        {

            // Set it

            $this->smtp	= $smtp;

        }

        // Else set details

        else
        {

            // SMTP Settings

            $this->smtp		= array (
                'server'		=> defined ('EMAIL_SERVER')? EMAIL_SERVER : NULL,
                'port'			=> defined ('EMAIL_PORT')? EMAIL_PORT : NULL,
                'domain'		=> defined ('EMAIL_DOMAIN')? EMAIL_DOMAIN : NULL,
                'username'		=> defined ('EMAIL_USERNAME')? EMAIL_USERNAME : NULL,
                'password'		=> defined ('EMAIL_PASSWORD')? EMAIL_PASSWORD : NULL
            );

        }

        // Set stream mode

        $this->_useStream	= TRUE;

        // Reset NL

        $this->_nl			= "\r\n";

    }
266606
public function SmtpConnect() {
    if ($this->smtp === null) {
      $this->smtp = new SMTP();
    }

    $this->smtp->Timeout = $this->Timeout;
    $this->smtp->do_debug = $this->SMTPDebug;
    $hosts = explode(';', $this->Host);
    $index = 0;
    $connection = $this->smtp->Connected();
    $rtn = true;

    // Retry while there is no connection
    try {
      while($index < count($hosts) && !$connection) {
        $hostinfo = array();
        if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
          $host = $hostinfo[1];
          $port = $hostinfo[2];
        } else {
          $host = $hosts[$index];
          $port = $this->Port;
        }

        $tls = ($this->SMTPSecure == 'tls');
        $ssl = ($this->SMTPSecure == 'ssl');

        if ($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) {

          $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname());
          $this->smtp->Hello($hello);

          if ($tls) {
            if (!$this->smtp->StartTLS()) {
              $rtn = false;
              throw new phpmailerException($this->Lang('tls'));
            }

            //We must resend HELO after tls negotiation
            $this->smtp->Hello($hello);
          }

          $connection = true;
          if ($this->SMTPAuth) {
            if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType,
                                           $this->Realm, $this->Workstation)) {
              $rtn = false;
              throw new phpmailerException($this->Lang('authenticate'));
            }
          }
        }
        $index++;
      }
      if (!$connection) {
        $rtn = false;
        throw new phpmailerException($this->Lang('connect_host'));
      }
    } catch (phpmailerException $e) {
      $this->smtp->Reset();
      if ($this->exceptions) {
        throw $e;
      }
      $rtn = false;
    }
    return $rtn;
  }
853937
public function sendEmail($emailFrom, $fromName, $emailTo, $toName = '', $replyTo = null, $subject, $message_html, $message_text = null, $transportConfig = null) {

	    $html = new MimePart($message_html);
	    $html->type = 'text/html';

	    $body = new MimeMessage();
	    
	    if ($message_text!=null){
	        
	        // Add Alternative Email Text Content
    	    $text = new MimePart($message_text);
    	    $text->type = 'text/plain';
    	    
    	    $body->addPart($html,$text);
    	    
	    }else{
	        $body->addPart($html);
	    }
	    
	    $message = new Message();
	    $message->setFrom($emailFrom, $fromName);
	    $message->addTo($emailTo);
	    $message->setSubject($subject);
	    $message->setEncoding('UTF-8');
	    $message->setSender($emailTo, $toName);
	    $message->setBody($body);
	    if ($replyTo!=null){
	        $message->addReplyTo($replyTo);
	    }

        $transport = new Sendmail();

        if(is_array($transportConfig) && $transportConfig) {
            /**
             * Program executes these lines when user passes
             * custom Transport Configuration Options ($transportConfig)
             * to specify their own Mailing Service Provider
             */
            try{
                // Setup SMTP transport using LOGIN authentication
                $transport = new SmtpTransport();
                $options   = new SmtpOptions(array(
                    'name'              => $transportConfig['name'],
                    'host'              => $transportConfig['host'],
                    'connection_class'  => $transportConfig['connectionClass'],
                    'connection_config' => array(
                        'username' => $transportConfig['username'],
                        'password' => $transportConfig['password'],
                        'ssl' => $transportConfig['ssl'],
                    ),
                    'port' => $transportConfig['port'],
                ));
                $transport->setOptions($options);
            }
            catch (\Exception $exception){
                throw new \Exception($exception->getMessage());
            }
        }

        $transport->send($message);
	}
686002
public function debug_handler(&$smtp, $message)
    {
        // catch AUTH commands and set anonymization flag for subsequent sends
        if (preg_match('/^Send: AUTH ([A-Z]+)/', $message, $m)) {
            $this->anonymize_log = $m[1] == 'LOGIN' ? 2 : 1;
        }
        // anonymize this log entry
        else if ($this->anonymize_log > 0 && strpos($message, 'Send:') === 0 && --$this->anonymize_log == 0) {
            $message = sprintf('Send: ****** [%d]', strlen($message) - 8);
        }

        if (($len = strlen($message)) > self::DEBUG_LINE_LENGTH) {
            $diff    = $len - self::DEBUG_LINE_LENGTH;
            $message = substr($message, 0, self::DEBUG_LINE_LENGTH)
                . "... [truncated $diff bytes]";
        }

        rcube::write_log('smtp', preg_replace('/\r\n$/', '', $message));
    }
1049811
public function send(array $args) {
        if (!$this->_validateArgs($args)) {
            return;
        }

        $mailer = new Garp_Mailer;

        if (getenv('CLI_EMAIL_SENDER')) {
            $mailer->setFromAddress(getenv('CLI_EMAIL_SENDER'));
        }

        $email = array(
            'to' => $args['to'],
            'subject' => $args['subject'],
            'message' => $args['message'],
        );

        try {
            $mailer->send($email);
            Garp_Cli::lineOut('Email sent!');
        } catch(Exception $e) {
            Garp_Cli::errorOut($e->getMessage());
        }
    }
493014
public function sendMail(): void
    {
        if ($this->use_smtp) {
            $mailer = new SmtpMailer([
                'host' => $this->email_host,
                'username' => $this->email_username,
                'password' => $this->email_password,
                'secure' => $this->email_security
            ]);
        } else {
            $mailer = new SendmailMailer();
        }
        $mailer->send($this->email);
    }
473174
private static function check($smtp)
    {
        exception_if(empty($smtp->host), SmtpParameterNotFoundException::class, 'host');
        exception_if(empty($smtp->port), SmtpParameterNotFoundException::class, 'port');
        exception_if(empty($smtp->encryption), SmtpParameterNotFoundException::class, 'encryption');
        exception_if(empty($smtp->username), SmtpParameterNotFoundException::class, 'username');
        exception_if(empty($smtp->password), SmtpParameterNotFoundException::class, 'password');
        exception_if(empty($smtp->sender_email), SmtpParameterNotFoundException::class, 'sender email');
        exception_if(empty($smtp->sender_name), SmtpParameterNotFoundException::class, 'sender name');

        return true;
    }
1345853
public function setMail($mail)
    {
        if (!$this->validMail($mail)) {
            return false;
        }

        if ($this->setMailStatement === null) {
            $this->setMailStatement = $this->connection->prepare("UPDATE User SET mail = ? WHERE username = ?");
            $this->setMailStatement->bindParam(1, $this->mail);
            $this->setMailStatement->bindParam(2, $this->username);
        }
        $this->mail = $mail;
        $this->setMailStatement->execute();
        return true;
    }
1148456
public function sendMessage(Message $msg)
    {
        if (is_callable($this->sendMessageFunction)) {
            call_user_func_array($this->sendMessageFunction, [$msg]);
        }
    }
1362418
public function send( CCMail $mail )
	{
		// create new phpmailer instance
		$driver = new PHPMailer\PHPMailer();
		
		// set the charset
		$driver->CharSet = 'utf-8'; 
		
		// set the xmailer tag
		$driver->XMailer = "ClanCatsFramework 2.0 Mail / PHPMailer ".$driver->Version;
		
		// get the mail data as array
		$mail_data = $mail->export_data();
		
		// from address and name
		list( $from_email, $from_name ) = $mail_data['from'];
		
		$driver->From = $from_email;
		if ( !is_null( $from_name ) )
		{
			$driver->FromName = $from_name;
		}
		
		// set the recipients
		foreach( $mail_data['to'] as $email => $name )
		{
			$driver->AddAddress( $email, $name );
		}
		
		// set bcc
		foreach( $mail_data['bcc'] as $email => $name )
		{
			$driver->addBCC( $email, $name );
		}
		
		// set cc
		foreach( $mail_data['cc'] as $email => $name )
		{
			$driver->addCC( $email, $name );
		}
		
		// add attachments
		foreach( $mail_data['attachments'] as $path => $name )
		{
			$driver->addAttachment( $path, $name );
		}
		
		// set the subject
		$driver->Subject = $mail_data['subject'];
		
		// set the message
		$driver->Body = $mail_data['message'];
		$driver->AltBody = $mail_data['plaintext'];
		$driver->IsHTML( !$mail_data['is_plaintext'] );
		
		// setup the driver
		$this->setup_driver( $driver );
		
		if( !$driver->Send() ) 
		{
			throw new Exception( "Mail failure: ". $driver->ErrorInfo );
		}
	}
440234
static function send( eZMail $mail )
    {
        $ini = eZINI::instance();

        $transportType = trim( $ini->variable( 'MailSettings', 'Transport' ) );

        $optionArray = array( 'iniFile'      => 'site.ini',
                              'iniSection'   => 'MailSettings',
                              'iniVariable'  => 'TransportAlias',
                              'handlerIndex' => strtolower( $transportType ) );
        $options = new ezpExtensionOptions( $optionArray );
        $transportClass = eZExtension::getHandlerClass( $options );

        if ( !is_object( $transportClass ) )
        {
            eZDebug::writeError( "No class available for mail transport type '$transportType', cannot send mail", __METHOD__ );
        }
        return $transportClass->sendMail( $mail );
    }
817485
protected function _sendMail()
    {
        $file = $this->_path . DIRECTORY_SEPARATOR . call_user_func($this->_callback, $this);

        if (!is_writable(dirname($file))) {
            // require_once 'Zend/Mail/Transport/Exception.php';
            throw new Zend_Mail_Transport_Exception(sprintf(
                'Target directory "%s" does not exist or is not writable',
                dirname($file)
            ));
        }

        $email = $this->header . $this->EOL . $this->body;

        if (!file_put_contents($file, $email)) {
            // require_once 'Zend/Mail/Transport/Exception.php';
            throw new Zend_Mail_Transport_Exception('Unable to send mail');
        }
    }
105587
public function send(Zend_Mail $mail)
    {
        $this->_isMultipart = false;
        $this->_mail        = $mail;
        $this->_parts       = $mail->getParts();
        $mime               = $mail->getMime();

        // Build body content
        $this->_buildBody();

        // Determine number of parts and boundary
        $count    = count($this->_parts);
        $boundary = null;
        if ($count < 1) {
            /**
             * @see Zend_Mail_Transport_Exception
             */
            // require_once 'Zend/Mail/Transport/Exception.php';
            throw new Zend_Mail_Transport_Exception('Empty mail cannot be sent');
        }

        if ($count > 1) {
            // Multipart message; create new MIME object and boundary
            $mime     = new Zend_Mime($this->_mail->getMimeBoundary());
            $boundary = $mime->boundary();
        } elseif ($this->_isMultipart) {
            // multipart/alternative -- grab boundary
            $boundary = $this->_parts[0]->boundary;
        }

        // Determine recipients, and prepare headers
        $this->recipients = implode(',', $mail->getRecipients());
        $this->_prepareHeaders($this->_getHeaders($boundary));

        // Create message body
        // This is done so that the same Zend_Mail object can be used in
        // multiple transports
        $message = new Zend_Mime_Message();
        $message->setParts($this->_parts);
        $message->setMime($mime);
        $this->body = $message->generateMessage($this->EOL);

        // Send to transport!
        $this->_sendMail();
    }
1239469
protected function connect(): void
    {
        $this->connection = @\stream_socket_client( // @ is escalated to exception
            ($this->secure === 'ssl' ? 'ssl://' : '') . $this->host . ':' . $this->port,
            $errno, $error, $this->timeout, STREAM_CLIENT_CONNECT, $this->context
        );
        if (!$this->connection) {
            throw new SmtpException($error ?: error_get_last()['message'], $errno);
        }
        \stream_set_timeout($this->connection, $this->timeout, 0);
        $this->read(); // greeting

        $this->write("EHLO {$this->clientHost}");
        $ehloResponse = $this->read();
        if ((int) $ehloResponse !== 250) {
            $this->write("HELO {$this->clientHost}", 250);
        }

        if ($this->secure === 'tls') {
            $this->write('STARTTLS', 220);
            if (!\stream_socket_enable_crypto($this->connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
                throw new SmtpException('Unable to connect via TLS.');
            }
            $this->write("EHLO {$this->clientHost}", 250);
        }

        $password = $this->getPassword();
        if ($this->username !== '' && $password !== '') {
            $authMechanisms = [];
            if (\preg_match('~^250[ -]AUTH (.*)$~im', $ehloResponse, $matches)) {
                $authMechanisms = \explode(' ', \trim($matches[1]));
            }

            if (\in_array('PLAIN', $authMechanisms, true)) {
                $credentials = $this->username . "\0" . $this->username . "\0" . $password;
                $this->write('AUTH PLAIN ' . \base64_encode($credentials), 235, 'PLAIN credentials');
            } else {
                $this->write('AUTH LOGIN', 334);
                $this->write(\base64_encode($this->username), 334, 'username');
                $this->write(\base64_encode($password), 235, 'password');
            }
        }
    }
1059781
public function sendEmail($email)
    {
        $user = $this->users->where('email', $email)->first();

        if (! is_null($user)) {
            $user->generatePasswordResetToken();
        }
    }
73471
public function send()
    {
        // if no recipients found, skipping sending
        if (count($this->getRecipient()) < 1) {
            return false;
        }

        $myConfig = Registry::getConfig();
        $this->setCharSet();

        if ($this->_getUseInlineImages()) {
            $this->_includeImages(
                $myConfig->getImageUrl(),
                $myConfig->getImageUrl(false, false),
                $myConfig->getPictureUrl(null, false),
                $myConfig->getImageDir(),
                $myConfig->getPictureDir(false)
            );
        }

        $this->_makeOutputProcessing();

        // try to send mail via SMTP
        if ($this->getMailer() == 'smtp') {
            $ret = $this->_sendMail();

            // if sending failed, try to send via mail()
            if (!$ret) {
                // failed sending via SMTP, sending notification to shop owner
                $this->_sendMailErrorMsg();

                // trying to send using standard mailer
                $this->setMailer('mail');
                $ret = $this->_sendMail();
            }
        } else {
            // sending mail via mail()
            $this->setMailer('mail');
            $ret = $this->_sendMail();
        }

        if (!$ret) {
            // failed sending, giving up, trying to send notification to shop owner
            $this->_sendMailErrorMsg();
        }

        return $ret;
    }
343518
public function send(Message $mail): void
    {
        $tmp = clone $mail;
        $tmp->setHeader('Bcc', null);
        $data = $tmp->generateMessage();

        try {
            if (!$this->connection) {
                $this->connect();
            }

            if (
                ($from = $mail->getHeader('Return-Path'))
                || ($from = \array_keys((array) $mail->getHeader('From'))[0])
            ) {
                $this->write("MAIL FROM:<$from>", 250);
            }

            foreach (\array_merge(
                         (array) $mail->getHeader('To'),
                         (array) $mail->getHeader('Cc'),
                         (array) $mail->getHeader('Bcc')
                     ) as $email => $name) {
                $this->write("RCPT TO:<$email>", [250, 251]);
            }

            $this->write('DATA', 354);
            $data = \preg_replace('#^\.#m', '..', $data);
            $this->write($data);
            $this->write('.', 250);

            if (!$this->persistent) {
                $this->write('QUIT', 221);
                $this->disconnect();
            }
        } catch (SmtpException $e) {
            if ($this->connection) {
                $this->disconnect();
            }
            throw $e;
        }
    }