[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Copyright 2013-2014 Horde LLC (http://www.horde.org/) 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * o Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * o Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * o The names of the authors may not be used to endorse or promote 16 * products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * @category Horde 32 * @copyright 2013-2014 Horde LLC 33 * @license http://www.horde.org/licenses/bsd New BSD License 34 * @package Mail 35 */ 36 37 /** 38 * SMTP implementation using Horde_Smtp. 39 * 40 * @author Michael Slusarz <slusarz@horde.org> 41 * @category Horde 42 * @copyright 2013-2014 Horde LLC 43 * @license http://www.horde.org/licenses/bsd New BSD License 44 * @package Mail 45 */ 46 class Horde_Mail_Transport_Smtphorde extends Horde_Mail_Transport 47 { 48 /** 49 * Send the message as 8bit? 50 * 51 * @var boolean 52 */ 53 public $send8bit = false; 54 55 /** 56 * SMTP object. 57 * 58 * @var Horde_Smtp 59 */ 60 protected $_smtp = null; 61 62 /** 63 * Constructor. 64 * 65 * @param array $params Additional parameters: 66 * <ul> 67 * <li> 68 * debug: (string) If set, will output debug information to the stream 69 * provided. The value can be any PHP supported wrapper that 70 * can be opened via fopen(). 71 * DEFAULT: No debug output 72 * </li> 73 * <li> 74 * host: (string) The SMTP server. 75 * DEFAULT: localhost 76 * </li> 77 * <li> 78 * password: (string) The SMTP password. 79 * DEFAULT: NONE 80 * </li> 81 * <li> 82 * port: (string) The SMTP port. 83 * DEFAULT: 587 84 * </li> 85 * <li> 86 * secure: (string) Use SSL or TLS to connect. 87 * DEFAULT: No encryption 88 * <ul> 89 * <li>false (No encryption)</li> 90 * <li>'ssl' (Auto-detect SSL version)</li> 91 * <li>'sslv2' (Force SSL version 3)</li> 92 * <li>'sslv3' (Force SSL version 2)</li> 93 * <li>'tls' (TLS)</li> 94 * </ul> 95 * </li> 96 * <li> 97 * timeout: (integer) Connection timeout, in seconds. 98 * DEFAULT: 30 seconds 99 * </li> 100 * <li> 101 * username: (string) The SMTP username. 102 * DEFAULT: NONE 103 * </li> 104 * </ul> 105 */ 106 public function __construct(array $params = array()) 107 { 108 $this->_params = $params; 109 110 /* SMTP requires CRLF line endings. */ 111 $this->sep = "\r\n"; 112 } 113 114 /** 115 */ 116 public function send($recipients, array $headers, $body) 117 { 118 /* If we don't already have an SMTP object, create one. */ 119 $this->getSMTPObject(); 120 121 $headers = $this->_sanitizeHeaders($headers); 122 list($from, $textHeaders) = $this->prepareHeaders($headers); 123 $from = $this->_getFrom($from, $headers); 124 125 $combine = Horde_Stream_Wrapper_Combine::getStream(array( 126 rtrim($textHeaders, $this->sep), 127 $this->sep . $this->sep, 128 $body 129 )); 130 131 try { 132 $this->_smtp->send($from, $recipients, $combine, array( 133 '8bit' => $this->send8bit 134 )); 135 } catch (Horde_Smtp_Exception $e) { 136 throw new Horde_Mail_Exception($e); 137 } 138 } 139 140 /** 141 * Connect to the SMTP server by instantiating a Horde_Smtp object. 142 * 143 * @return Horde_Smtp The SMTP object. 144 * @throws Horde_Mail_Exception 145 */ 146 public function getSMTPObject() 147 { 148 if (!$this->_smtp) { 149 $this->_smtp = new Horde_Smtp($this->_params); 150 try { 151 $this->_smtp->login(); 152 } catch (Horde_Smtp_Exception $e) { 153 throw new Horde_Mail_Exception($e); 154 } 155 } 156 157 return $this->_smtp; 158 } 159 160 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |