50 require_once
'Net/SMTP.php';
150 'not_connected' => array(
152 'msg' =>
'Could not connect to any mail server ({HOST}) at port {PORT} to send mail to {RCPT}.'
154 'failed_vrfy_rcpt' => array(
156 'msg' =>
'Recipient "{RCPT}" could not be veryfied.'
158 'failed_set_from' => array(
160 'msg' =>
'Failed to set sender: {FROM}.'
162 'failed_set_rcpt' => array(
164 'msg' =>
'Failed to set recipient: {RCPT}.'
166 'failed_send_data' => array(
168 'msg' =>
'Failed to send mail to: {RCPT}.'
172 'msg' =>
'No from address has be provided.'
174 'send_data' => array(
176 'msg' =>
'Failed to create Net_SMTP object.'
180 'msg' =>
'No MX-record for {RCPT} found.'
182 'no_resolver' => array(
184 'msg' =>
'Could not start resolver! Install PEAR:Net_DNS or switch off "netdns"'
186 'failed_rset' => array(
188 'msg' =>
'RSET command failed, SMTP-connection corrupt.'
216 if (isset($params[
'mailname'])) {
217 $this->mailname = $params[
'mailname'];
220 if (function_exists(
'posix_uname')) {
221 $uname = posix_uname();
222 $this->mailname = $uname[
'nodename'];
227 if (isset($params[
'port'])) {
228 $this->_port = $params[
'port'];
230 $this->_port = getservbyname(
'smtp',
'tcp');
233 if (isset($params[
'timeout'])) $this->timeout = $params[
'timeout'];
234 if (isset($params[
'verp'])) $this->verp = $params[
'verp'];
235 if (isset($params[
'test'])) $this->test = $params[
'test'];
236 if (isset($params[
'peardebug'])) $this->test = $params[
'peardebug'];
237 if (isset($params[
'netdns'])) $this->withNetDns = $params[
'netdns'];
250 register_shutdown_function(array(&$this,
'__destruct'));
259 if (is_object($this->_smtp)) {
260 $this->_smtp->disconnect();
274 function send($recipients, $headers, $body)
276 if (!is_array($headers)) {
281 if (is_a(
$result,
'PEAR_Error')) {
287 if (is_a($headerElements,
'PEAR_Error')) {
288 return $headerElements;
290 list($from, $textHeaders) = $headerElements;
293 if (!empty($headers[
'Return-Path'])) {
294 $from = $headers[
'Return-Path'];
302 if (is_a($recipients,
'PEAR_Error')) {
306 foreach ($recipients as $rcpt) {
307 list($user, $host) = explode(
'@', $rcpt);
309 $mx = $this->
_getMx($host);
310 if (is_a($mx,
'PEAR_Error')) {
315 $info = array(
'rcpt' => $rcpt);
320 foreach ($mx as $mserver => $mpriority) {
321 $this->_smtp =
new Net_SMTP($mserver, $this->port, $this->mailname);
325 $this->_smtp->setDebug(
true);
329 $res = $this->_smtp->connect($this->timeout);
330 if (is_a(
$res,
'PEAR_Error')) {
344 'host' => implode(
', ', array_keys($mx)),
345 'port' => $this->port,
353 $res = $this->_smtp->vrfy($rcpt);
354 if (is_a(
$res,
'PEAR_Error')) {
355 $info = array(
'rcpt' => $rcpt);
356 return $this->
_raiseError(
'failed_vrfy_rcpt', $info);
362 $res = $this->_smtp->mailFrom($from, $args);
363 if (is_a(
$res,
'PEAR_Error')) {
364 $info = array(
'from' => $from);
365 return $this->
_raiseError(
'failed_set_from', $info);
369 $res = $this->_smtp->rcptTo($rcpt);
370 if (is_a(
$res,
'PEAR_Error')) {
371 $info = array(
'rcpt' => $rcpt);
372 return $this->
_raiseError(
'failed_set_rcpt', $info);
377 $result = $this->_smtp->rset();
378 $res = $this->_smtp->rset();
379 if (is_a(
$res,
'PEAR_Error')) {
383 $this->_smtp->disconnect();
389 $res = $this->_smtp->data(
"$textHeaders\r\n$body");
390 if (is_a(
$res,
'PEAR_Error')) {
391 $info = array(
'rcpt' => $rcpt);
392 return $this->
_raiseError(
'failed_send_data', $info);
395 $this->_smtp->disconnect();
415 if ($this->withNetDns) {
417 if (is_a(
$res,
'PEAR_Error')) {
421 $response = $this->resolver->query($host,
'MX');
426 foreach ($response->answer as $rr) {
427 if ($rr->type ==
'MX') {
428 $mx[$rr->exchange] = $rr->preference;
435 if (!getmxrr($host, $mxHost, $mxWeight)) {
438 for ($i = 0; $i < count($mxHost); ++$i) {
439 $mx[$mxHost[$i]] = $mxWeight[$i];
455 if (is_object($this->resolver)) {
459 if (!include_once
'Net/DNS.php') {
463 $this->resolver =
new Net_DNS_Resolver();
465 $this->resolver->test = 1;
483 $code = $this->errorCode[$id][
'code'];
484 $msg = $this->errorCode[$id][
'msg'];
491 foreach ($info as $key => $value) {
492 array_push($search,
'{' . strtoupper($key) .
'}');
493 array_push($replace, $value);
496 $msg = str_replace($search, $replace, $msg);