48 define(
'PEAR_MAIL_SMTP_ERROR_CREATE', 10000);
51 define(
'PEAR_MAIL_SMTP_ERROR_CONNECT', 10001);
54 define(
'PEAR_MAIL_SMTP_ERROR_AUTH', 10002);
57 define(
'PEAR_MAIL_SMTP_ERROR_FROM', 10003);
60 define(
'PEAR_MAIL_SMTP_ERROR_SENDER', 10004);
63 define(
'PEAR_MAIL_SMTP_ERROR_RECIPIENT', 10005);
66 define(
'PEAR_MAIL_SMTP_ERROR_DATA', 10006);
193 if (isset($params[
'host'])) $this->host = $params[
'host'];
194 if (isset($params[
'port'])) $this->port = $params[
'port'];
195 if (isset($params[
'auth'])) $this->auth = $params[
'auth'];
196 if (isset($params[
'username'])) $this->username = $params[
'username'];
197 if (isset($params[
'password'])) $this->password = $params[
'password'];
198 if (isset($params[
'localhost'])) $this->localhost = $params[
'localhost'];
199 if (isset($params[
'timeout'])) $this->timeout = $params[
'timeout'];
200 if (isset($params[
'debug'])) $this->debug = (bool)$params[
'debug'];
201 if (isset($params[
'persist'])) $this->persist = (
bool)$params[
'persist'];
202 if (isset($params[
'pipelining'])) $this->pipelining = (
bool)$params[
'pipelining'];
205 if (isset($params[
'verp'])) {
209 register_shutdown_function(array(&$this,
'_Mail_smtp'));
245 function send($recipients, $headers, $body)
253 if (!is_array($headers)) {
260 if (is_a($headerElements,
'PEAR_Error')) {
261 $this->_smtp->rset();
262 return $headerElements;
264 list($from, $textHeaders) = $headerElements;
269 if (!empty($headers[
'Return-Path'])) {
270 $from = $headers[
'Return-Path'];
274 $this->_smtp->rset();
280 if (!empty($this->_extparams)) {
281 foreach ($this->_extparams as $key => $val) {
282 $params .=
' ' . $key . (is_null($val) ?
'' :
'=' . $val);
286 $error = $this->
_error(
"Failed to set sender: $from",
$res);
287 $this->_smtp->rset();
292 if (is_a($recipients,
'PEAR_Error')) {
293 $this->_smtp->rset();
297 foreach ($recipients as $recipient) {
298 $res = $this->_smtp->rcptTo($recipient);
299 if (is_a(
$res,
'PEAR_Error')) {
300 $error = $this->
_error(
"Failed to add recipient: $recipient",
$res);
301 $this->_smtp->rset();
307 $res = $this->_smtp->data($textHeaders .
"\r\n\r\n" . $body);
308 list(,$args) = $this->_smtp->getResponse();
310 if (preg_match(
"/Ok: queued as (.*)/", $args, $queued)) {
311 $this->queued_as = $queued[1];
316 $this->greeting = $this->_smtp->getGreeting();
318 if (is_a(
$res,
'PEAR_Error')) {
319 $error = $this->
_error(
'Failed to send data',
$res);
320 $this->_smtp->rset();
325 if ($this->persist ===
false) {
344 if (is_object($this->_smtp) !==
false) {
348 include_once
'Net/SMTP.php';
349 $this->_smtp = &
new Net_SMTP($this->host,
354 if (is_object($this->_smtp) ===
false) {
361 $this->_smtp->setDebug(
true);
366 $error = $this->
_error(
'Failed to connect to ' .
367 $this->host .
':' . $this->port,
374 $method = is_string($this->auth) ? $this->auth :
'';
379 $error = $this->
_error(
"$method authentication failure",
381 $this->_smtp->rset();
400 $this->_extparams[$keyword] = $value;
414 if (is_object($this->_smtp) && $this->_smtp->disconnect()) {
419 return ($this->_smtp === null);
436 list($code, $response) = $this->_smtp->getResponse();
440 .
' [SMTP: ' . $error->getMessage()
441 .
" (code: $code, response: $response)]";
const PEAR_MAIL_SMTP_ERROR_CREATE
Error: Failed to create a Net_SMTP object.
_error($text, &$error)
Build a standardized string describing the current SMTP error.
& getSMTPObject()
Connect to the SMTP server by instantiating a Net_SMTP object.
disconnect()
Disconnect and destroy the current SMTP connection.
const PEAR_MAIL_SMTP_ERROR_DATA
Error: Failed to send data.
parseRecipients($recipients)
Take a set of recipients and parse them, returning an array of bare addresses (forward paths) that ca...
const PEAR_MAIL_SMTP_ERROR_FROM
Error: No From: address has been provided.
_sanitizeHeaders(&$headers)
Sanitize an array of mail headers by removing any additional header strings present in a legitimate h...
Mail_smtp($params)
Constructor.
_Mail_smtp()
Destructor implementation to ensure that we disconnect from any potentially-alive persistent SMTP con...
internal PHP-mail() implementation of the PEAR Mail:: interface.
send($recipients, $headers, $body)
Implements Mail::send() function using SMTP.
prepareHeaders($headers)
Take an array of mail headers and return a string containing text usable in sending a message...
const PEAR_MAIL_SMTP_ERROR_RECIPIENT
Error: Failed to add recipient.
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object's de...
const PEAR_MAIL_SMTP_ERROR_AUTH
Error: SMTP authentication failure.
addServiceExtensionParameter($keyword, $value=null)
Add parameter associated with a SMTP service extension.
const PEAR_MAIL_SMTP_ERROR_SENDER
Error: Failed to set sender.
$debug
Turn on Net_SMTP debugging?
isError($data, $code=null)
Tell whether a value is a PEAR error.
const PEAR_MAIL_SMTP_ERROR_CONNECT
Error: Failed to connect to SMTP server.