Пример #1
0
 public static function send(SoxMail $mail, $debug = false)
 {
     // $to, $cc, $bcc & $all contain the address that will actually be sent to (filtered by debug settings).
     // $origTo, $origCC, $origBCC, & $origAll contain the original addressees before filtering.
     $to = $origTo = $mail->to();
     $cc = $origCC = $mail->cc();
     $bcc = $origBCC = $mail->bcc();
     $origAll = $to + $cc + $bcc;
     if (self::$debug_to) {
         foreach ($to as $email => $name) {
             if (!in_array($email, self::$debug_to)) {
                 unset($to[$email]);
             }
         }
         foreach ($cc as $email => $name) {
             if (!in_array($email, self::$debug_to)) {
                 unset($cc[$email]);
             }
         }
         foreach ($bcc as $email => $name) {
             if (!in_array($email, self::$debug_to)) {
                 unset($bcc[$email]);
             }
         }
     }
     $all = $to + $cc + $bcc;
     $origSubject = $mail->subject();
     $mail->tls(true, self::$smtp_user, self::$smtp_password);
     if ($all) {
         $mail->to($to, false);
         $mail->cc($cc, false);
         $mail->bcc($bcc, false);
         $c = new Sox(self::$smtp_host, self::$smtp_port);
         $c->debug($debug);
         $mail->send($c, self::$default_helo);
     }
     if (self::$debug_all) {
         $origTo = SoxMail::emailArrayToString($origTo);
         $origCC = SoxMail::emailArrayToString($origCC);
         $origBCC = SoxMail::emailArrayToString($origBCC);
         $origAll = SoxMail::emailArrayToString($origAll);
         $mail->to(self::$debug_all, false);
         $mail->cc('', false);
         $mail->bcc('', false);
         $mail->subject("Email sent to: {$origTo}");
         $header = "To: {$origTo}\n" . "CC: {$origCC}\n" . "BCC: {$origBCC}\n" . "Delivered To: " . ($all ? SoxMail::emailArrayToString($all) . "  (Yes, it was really sent to them)" : '(nobody)') . "\n" . "Subject: {$origSubject}\n\n\n";
         $mail->text($header . $mail->text());
         if ($mail->html()) {
             $mail->html(nl2br(htmlentities($header)) . $mail->html());
         }
         $c = new Sox(self::$smtp_host, self::$smtp_port);
         $c->debug($debug);
         $mail->send($c, self::$default_helo);
     }
 }
Пример #2
0
 public function __construct($url, $postData = null, $timeout = 10)
 {
     if (is_string($url)) {
         $url = new SoxURL($url);
     }
     $this->url = $url;
     $this->newline = "\r\n";
     $this->method = $postData === null ? 'GET' : 'POST';
     $this->request = new SoxMIME();
     $this->request->Host = $url->host;
     $this->request->{'User-Agent'} = 'Saffyre Sox Client 1.0';
     $this->request->{'Content-Length'} = true;
     $this->request->body = $postData;
     parent::__construct($url->host, $url->port ? $url->port : 80, $timeout, false);
 }
Пример #3
0
 private function read(Sox $conn)
 {
     do {
         $line = $conn->readline();
     } while (substr($line, 3, 1) != ' ');
 }