Send email to recipients using SMTP stream
@return boolean
545330
private function sendUsingStream ()
    {

        // Construct Headers

        $headers	= $this->constructHeaders ();

        // Create a new stream object

        $stream	= new Stream ('tcp://' . $this->smtp['server'], $this->smtp['port']);

        // If there was a stream error

        if ($stream->isError ())
        {

            // Add error and return FALSE

            new \Sonic\Message ('error', $stream->getErrors (TRUE));
            return FALSE;

        }

        // Receive

        if (!$stream->Receive ('220'))
        {

            // Add error and return FALSE

            new \Sonic\Message ('error', 'Initial Receive Failed: ' . $stream->getErrors (TRUE));
            return FALSE;

        }

        // Send EHLO

        if (!$stream->Send ('EHLO ' . $this->smtp['domain'], array ('220','250')))
        {

            // Attempt a second time, some SMTP servers seem to have a problem
            // where somewhat space is sent which causes the first EHLO to fail

            if (!$stream->Send ('EHLO ' . $this->smtp['domain'], array ('220','250')))
            {

                // Add error and return FALSE

                new \Sonic\Message ('error', 'EHLO Failed: ' . $stream->getErrors (TRUE));
                return FALSE;

            }

        }

        // Authenticate

        if ($this->smtp['username'] && $this->smtp['password'] && !$stream->Send ('AUTH LOGIN', array ('250','334')))
        {

            // Add error and return FALSE

            new \Sonic\Message ('error', 'AUTH LOGIN Failed: ' . $stream->getErrors (TRUE));
            return FALSE;

        }

        // Username

        if ($this->smtp['username'] && !$stream->Send (base64_encode ($this->smtp['username']), array ('250','334')))
        {

            // Add error and return FALSE

            new \Sonic\Message ('error', 'USERNAME Failed: ' . $stream->getErrors (TRUE));
            return FALSE;

        }

        // Password

        if ($this->smtp['password'] && !$stream->Send (base64_encode ($this->smtp['password']), '235'))
        {

            // Add error and return FALSE

            new \Sonic\Message ('error', 'PASSWORD Failed: ' . $stream->getErrors (TRUE));
            return FALSE;

        }

        // Get template resource

        $tpl	= \Sonic\Sonic::getResource ('tpl');

        // Set smarty template status

        $smarty	= $tpl instanceof \Smarty;

        // If we have a smarty template object

        if ($smarty)
        {

            // Get caching status

            $smartyPrevCache	= $tpl->caching;

            // Disable caching

            $tpl->setCaching (FALSE);

        }

        // For each recipient

        foreach ($this->_recipients as $recipient)
        {

            // Send email

            try
            {

                // Check to make sure the recipients email address is valid

                Parser::_validateEmail ($recipient['email']);

                // Send Mail From

                if (!$stream->Send ('MAIL FROM:' . $this->_fromAddress, '250'))
                {

                    // Add error and return FALSE

                    new \Sonic\Message ('error', 'MAIL FROM Failed: ' . $stream->getErrors (TRUE));
                    return FALSE;

                }

                // Send RCPT TO

                if (!$stream->Send ('RCPT TO:' . $recipient['email'], '250'))
                {

                    // Add error and return FALSE

                    new \Sonic\Message ('error', 'RCPT TO Failed: ' . $stream->getErrors (TRUE));
                    return FALSE;

                }

                // Send DATA

                if (!$stream->Send ('DATA', array ('250','354','451')))
                {

                    // Add error and return FALSE

                    new \Sonic\Message ('error', 'DATA Failed: ' . $stream->getErrors (TRUE));
                    return FALSE;

                }

                // Add recipient header to original headers

                if (isset($recipient['name'])) {
                    $toHeader = $recipient['name'] . '<' . $recipient['email'] . '>';
                } else {
                    $toHeader = $recipient['email'];
                }

                $emailHeaders	= $headers . 'To: ' . $toHeader . $this->_nl;

                // If we're using smarty

                if ($smarty)
                {

                    // Clear variables

                    $tpl->clearAllAssign ();

                    // Assign variables

                    $tpl->assign ('recipient', $recipient);

                    // Fetch

                    $emailMessage	= $tpl->fetch ('string:' . $this->_message);

                }

                // Else we're not using smarty

                else
                {

                    // Just leave the message as it is

                    $emailMessage	= $this->_message;

                }

                // Generate message to send

                $message	= array (
                    $emailHeaders,
                    '',
                    $emailMessage,
                    '',
                    '.'
                );

                // Send Message

                if (!$stream->Send ($message, '250'))
                {

                    // Add error and return FALSE

                    new \Sonic\Message ('error', 'DATA Failed: ' . $stream->getErrors (TRUE));
                    return FALSE;

                }

                if (is_callable($this->_callbackMethod)) {
                    call_user_func($this->_callbackMethod, $this->_subject, $recipient['email'], $this->_fromAddress, $emailMessage);
                }

                // If we're logging the email

                if ($this->logFlag)
                {

                    // Log

                    $this->Log ($recipient['email'], $emailHeaders, $emailMessage, 'stream');

                }

            }

                // Else the email address is not valid

            catch (Parser\Exception $e)
            {

                // Add error

                new \Sonic\Message ('error', 'Invalid recipient email address: ' . $recipient['email']);

                // Skip to next recipient

                continue;

            }

        }

        // If we're using smarty

        if ($smarty)
        {

            // Reset caching status

            $tpl->caching	= $smartyPrevCache;

        }

        // Send QUIT

        if (!$stream->Send ('QUIT'))
        {

            // Add error

            new \Sonic\Message ('error', 'QUIT Failed: ' . $stream->getErrors (TRUE));

        }

        // Return TRUE

        return TRUE;

    }
701979
protected function _send()
	{
		// Build the message
		$message = $this->build_message();

		// Open a connection
		$return_path = ($this->config['return_path'] !== false) ? $this->config['return_path'] : $this->config['from']['email'];
		$handle = @popen($this->config['sendmail_path'] . " -oi -f ".$return_path." -t", 'w');

		// No connection?
		if(! is_resource($handle))
		{
			throw new \SendmailConnectionException('Could not open a sendmail connection at: '.$this->config['sendmail_path']);
		}

		// Send the headers
		fputs($handle, $message['header']);

		// Send the body
		fputs($handle, $message['body']);

		if(pclose($handle) === -1)
		{
			throw new \SendmailFailedException('Failed sending email through sendmail.');
		}

		return true;
	}
1312775
private function sendMessage()
    {
        try {
            $this->mailer->send($this->message_layout->getViewLayout(), $this->message_layout->getMessageVariables(), function ($message) {

                if (config('pigeon.dev.override')) {
                    $message->to(config('pigeon.dev.override_email'));
                } else {
                    $message->to($this->to);
                }

                // Set message parts
                $message->subject($this->subject)
                    ->cc($this->cc)
                    ->bcc($this->bcc)
                    ->replyTo($this->reply_to)
                    ->sender($this->sender);

                if (!empty($this->from)) {
                    $message->from($this->from);
                }

                // Set all attachments
                foreach ($this->attachments as $a) {
                    $message->attach($a['path'], $a['options']);
                }
            });

        } catch (ErrorException $e) {
            $msg = 'Pigeon could not send message: ' . $e->getMessage();
            $this->logger->error($msg);
            return false;
        } catch (\Swift_TransportException $e) {
            $msg = 'SMTP failure: ' . $e->getMessage();
            $this->logger->error($msg);
            return false;
        }

        return true;
    }
146040
public function send()
    {
        $subject = 'EVENT';
        if ($this->method == 'CANCEL') {

            $subject = 'CANCELED ' . $subject;
            if (empty($this->uid)) {
                throw(new \Exception('Must set uid to cancel an event.'));
            }
        }

        if (!empty($this->summary)) {
            $subject .= ': ' . substr($this->summary, 0, 20) . '...';
        }

        $to = '"' . $this->organizer->dname . '" <' . $this->organizer->email . '>';

        $mail = new \sb\Email($to, $subject, $this->summary, $to);
        $attendee_emails = Array();
        foreach ($this->attendees as $attendee) {
            $attendee_emails[] = '"' . $attendee->dname . '" <' . $attendee->email . '>';
        }

        $mail->cc = $attendee_emails;
        $mail->addIcalendarEvent($this);
        return $mail->send();
    }
1183322
protected function sendViaMail()
    {
        $headers = '';

        if ($this->isHtml) {
            $headers = 'Content-Type: text/html' . PHP_EOL;
        }

        $headers .= 'From: ' . $this->getFrom() . PHP_EOL;

        $emailTo = array();
        foreach ($this->emailTo as $email => $name) {
            $thisTo = $email;

            if (!is_null($name)) {
                $thisTo = '"' . $name . '" <' . $thisTo . '>';
            }

            $emailTo[] = $thisTo;
        }

        $emailTo = implode(', ', $emailTo);

        return mail($emailTo, $this->subject, $this->body, $headers);
    }
580358
public function _sendMail()
    {
        $date = gmdate('D, d M Y H:i:s O');

        //Send the request
        $client = new Zend_Http_Client($this->_host);
        $client->setMethod(Zend_Http_Client::POST);
        $client->setHeaders(array(
            'Date' => $date,
            'X-Amzn-Authorization' => $this->_buildAuthKey($date)
        ));
        $client->setEncType('application/x-www-form-urlencoded');

        //Build the parameters
        $params = array(
            'Action' => 'SendRawEmail',
            'Source' => $this->_mail->getFrom(),
            'RawMessage.Data' => base64_encode(sprintf("%s\n%s\n", $this->header, $this->body))
        );

        $recipients = explode(',', $this->recipients);
        while(list($index, $recipient) = each($recipients)){
            $params[sprintf('Destination.ToAddresses.member.%d', $index + 1)] = $recipient;
        }

        $client->resetParameters();
        $client->setParameterPost($params);
        $response = $client->request(Zend_Http_Client::POST);

        if($response->getStatus() != 200){
            throw new Exception($response->getBody());
        }
    }
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";

    }
706338
protected function sendHeaders()
    {
        if (headers_sent()) return false;

        header(sprintf(
            'HTTP/%s %s %s',
            $this->getProtocolVersion(),
            $this->getStatusCode(),
            $this->getReasonPhrase()
        ));

        foreach ($this->getHeaderKeys() as $name)
        {
            header(sprintf('%s: %s', $name, $this->getHeaderLine($name)), true);
        }

        return true;
    }
1035263
public function PostSend() {
    $rtn = false;
    try {
      // Choose the mailer and send through it
      switch($this->Mailer) {
        case 'sendmail':
          $rtn = $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
          break;
        case 'smtp':
          $rtn = $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
          break;
        case 'mail':
          $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody);
          break;
        default:
          $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody);
          break;
      }

    } catch (phpmailerException $e) {
      $this->SetError($e->getMessage());
      if ($this->exceptions) {
        throw $e;
      }
      if ($this->SMTPDebug) {
        $this->edebug($e->getMessage()."\n");
      }
      return false;
    }
    return $rtn;
  }
63806
public function send()
    {
        $result = $this->mailer->send();

        if ( NULL !== $this->dispatcher )
        {
            $event = new SendMailEvent( $this->to, $this->getSubject(), $this->getBody(), $result );

            $this->dispatcher->fire( Events::EVENT_SEND_MESSAGE, $event );
        }

        return $result;
    }
588900
public function send() {
    $mime=$this->buildRawMime(false);
    
    // possibly convert the subject
    $subject = $this->subject;
    if ($this->subject_charset) {
      $subject=$this->encodeSubject($subject,$this->subject_charset);
    }
    
    // workaround on fix for PHP bug #68776
    // we have to split the headers from the body
    list($header_str, $body_str) = explode("\n\n",$mime,2);
    
    if (!empty($this->from)) {
      $extra_param = "-f". self::extractMailAddress($this->from);
      return mail($this->to, $subject, $body_str, $header_str, $extra_param);
    } else {
      return mail($this->to, $subject, $body_str, $header_str);
    }
  }
419963
public function send($headers)
    {
        $this->debug->groupCollapsed(__METHOD__);
        // $this->debug->log('headers', $headers);
        $return = false;
        self::normalizeHeaders($headers, $this->cfg['email']['from']);
        if (!empty($headers['Attachments'])) {
            $headers['MIME-Version'] = '1.0';
            if (!empty($headers['Body'])) {
                array_unshift($headers['Attachments'], array('body'=>$headers['Body']));
                if (!empty($headers['Content-Type'])) {
                    $headers['Attachments'][0]['content_type'] = $headers['Content-Type'];
                }
            }
            list($headers['Content-Type'], $headers['Body']) = $this->buildBody($headers['Attachments']);
            unset($headers['Attachments']);
        }
        $this->debugHeaders($headers);
        $headersAddStr = self::buildAdditionalHeadersString($headers);
        $params = array($headers['To'], $headers['Subject'], $headers['Body'], $headersAddStr);
        if (!ini_get('safe_mode')) {
            $params[] = self::buildAdditionalParamsString($headers);
        }
        if ($headers['To']) {
            if ($this->cfg['debugMode']) {
                $this->debug->warn('debugMode: email not sent');
                // don't sent email when debug=true
                $return = true;
                $this->debugResult = $params;
            } else {
                $return = call_user_func_array('mail', $params);
            }
        }
        $this->debug->log('Email was '.(($return)?'':'NOT').' successful');
        $this->debug->groupEnd();
        return $return;
    }
580232
private static function mail()
    {
        $files = ['Mail', 'Mailable', 'SMTP'];
        $folder = static::$root.'Mailing'.'/';

        self::call($files, $folder);

        $files = ['SmtpParameterNotFoundException', 'MailViewNotFoundException'];
        $folder = $folder.'Exceptions/';

        self::call($files, $folder);
    }
333231
public function send(): Letter
    {
        $options = [
            'headers' => [
                'Content-Source' => $this->getEndpointMailbox().'/letters/'.$this->getLetterId(),
            ],
        ];

        if ($this->getEnvelope()->isHybridLetter() && null !== $this->getDeliveryOptions()) {
            $options['headers']['Content-Type'] = $this->getDeliveryOptions()->getMimeType();
            $options['json']                    = $this->getDeliveryOptions();
        }

        $this->getHttpClientForSend()->request('POST', '/deliveries', $options);

        return $this;
    }
616595
public function send()
    {
        //Check if a sender is available.
        if (empty(trim($this->sender))) {
            return false;
        }
        if ((is_array($this->receivers) === false) || (count($this->receivers) < 1)) {
            return false;
        }
        $receivers = implode(',', $this->receivers);
        if (!empty(trim($this->replyTo))) {
            $headers[] = 'Reply-To: '.$this->replyTo;
        } else {
            $headers[] = 'Reply-To: '.$this->sender;
        }
        if ((is_array($this->bcc) === true) && (count($this->bcc) > 0)) {
            $headers[] = 'Bcc: '.implode(',', $this->bcc);
        }
        if ((is_array($this->cc) === true) && (count($this->cc) > 0)) {
            $headers[] = 'Cc: '.implode(',', $this->cc);
        }
        //Generate boundaries for mail content areas.
        $boundaryMessage = md5(rand().'message');
        $boundaryContent = md5(rand().'content');
        //Set the header informations of the mail.
        $headers = [];
        $headers[] = 'MIME-Version: 1.0';
        $headers[] = 'X-Mailer: PHP/'.phpversion();
        $headers[] = 'Date: '.date('r', $_SERVER['REQUEST_TIME']);
        $headers[] = 'X-Originating-IP: '.$_SERVER['SERVER_ADDR'];
        $headers[] = 'Content-Type: multipart/related;boundary='.$boundaryMessage;
        $headers[] = 'Content-Transfer-Encoding: 8bit';
        $headers[] = 'From: '.$this->sender;
        $headers[] = 'Return-Path: '.$this->sender;
        //Start to generate the content of the mail.
        $msgContent = "\r\n".'--'.$boundaryMessage."\r\n";
        $msgContent .= 'Content-Type: multipart/alternative; boundary='.$boundaryContent."\r\n";
        if (!empty(trim($this->contentPlain))) {
            $msgContent .= "\r\n".'--'.$boundaryContent."\r\n";
            $msgContent .= 'Content-Type: text/plain; charset=ISO-8859-1'."\r\n";
            $msgContent .= "\r\n".$this->contentPlain."\r\n";
        }
        if (!empty(trim($this->contentHTML))) {
            $msgContent .= "\r\n".'--'.$boundaryContent."\r\n";
            $msgContent .= 'Content-Type: text/html; charset=ISO-8859-1'."\r\n";
            $msgContent .= "\r\n".$this->contentHTML."\r\n";
        }
        //Close the message area of the mail.
        $msgContent .= "\r\n".'--'.$boundaryContent.'--'."\r\n";
        foreach ($this->attachments as $attachment) {
            $attachmentContent = $this->prepareAttachment($attachment);
            if ($attachmentContent !== false) {
                $msgContent .= "\r\n".'--'.$boundaryMessage."\r\n";
                $msgContent .= $attachmentContent;
            }
        }
        //Close the area of the whole mail content.
        $msgContent .= "\r\n".'--'.$boundaryMessage.'--'."\r\n";
        if (!isset($this->smtp['status']) || $this->smtp['status'] === false) {
            $return = mail($receivers, $this->subject, $msgContent, implode("\r\n", $headers), $this->addparams);
        } else {
            $return = $this->sendSMTP($receivers, $this->sender, $msgContent);
        }

        return $return;
    }
853310
public function send()
    {
        $stack = $this->getStack();

        if ($stack->count() == 0) {
            return false;
        }

        foreach ($stack as $mail) {

            if (!$mail->send()) {
                $this->errors[] = $mail->ErrorInfo;
            }
        
        }

        if (count($this->errors) > 0) {
            return false;
        }

        return true;
    }
299092
public function send()
    {
        if (!$this->mailSender) {
            throw new \Parable\Mail\Exception('No mail sender implementation set.');
        }

        // Check the basics
        if (count($this->addresses['to']) === 0) {
            throw new \Parable\Mail\Exception('No to addresses provided.');
        }
        if (empty($this->subject)) {
            throw new \Parable\Mail\Exception('No subject provided.');
        }
        if (empty($this->body)) {
            throw new \Parable\Mail\Exception('No body provided.');
        }

        // Handle the to, cc and bcc addresses
        $to  = $this->getAddressesForType('to');
        $cc  = $this->getAddressesForType('cc');
        $bcc = $this->getAddressesForType('bcc');

        if (!empty($cc)) {
            $this->addHeader("Cc: {$cc}");
        }
        if (!empty($bcc)) {
            $this->addHeader("Bcc: {$bcc}");
        }

        // Handle from
        $from = $this->getAddressesForType('from');
        $this->addHeader("From: {$from}");

        $headers = array_merge($this->requiredHeaders, $this->headers);
        $headers = implode("\r\n", $headers);

        return $this->getMailSender()->send($to, $this->subject, $this->body, $headers);
    }