Commit 41f706be authored by Yves Christian KPAKPO's avatar Yves Christian KPAKPO
Browse files

Update: merge mime mail class from notification to tools directory

parent 32462fc6
......@@ -96,6 +96,8 @@ class htmlMimeMail
*/
var $smtp_params;
var $sendmail_path;
/**
* Constructor function. Sets the headers
* if supplied.
......@@ -108,6 +110,7 @@ class htmlMimeMail
$this->html_images = array();
$this->headers = array();
$this->is_built = false;
$this->sendmail_path = '/usr/lib/sendmail -ti';
/**
* If you want the auto load functionality
......@@ -209,6 +212,14 @@ class htmlMimeMail
if (!is_null($pass)) $this->smtp_params['pass'] = $pass;
}
/**
* Sets sendmail path and options (optionally) (when directly piping to sendmail)
*/
function setSendmailPath($path)
{
$this->sendmail_path = $path;
}
/**
* Accessor function to set the text encoding
*/
......@@ -314,6 +325,14 @@ class htmlMimeMail
$this->text = $text;
}
/**
* Adds notification to
*/
function setNotification($mail)
{
$this->headers['Disposition-Notification-To'] = $mail;
}
/**
* Adds a html part to the mail.
* Also replaces image names with
......@@ -664,7 +683,7 @@ class htmlMimeMail
function send($recipients, $type = 'mail')
{
if (!defined('CRLF')) {
$this->setCrlf($type == 'mail' ? "\n" : "\r\n");
$this->setCrlf( ($type == 'mail' OR $type == 'sendmail') ? "\n" : "\r\n");
}
if (!$this->is_built) {
......@@ -701,6 +720,28 @@ class htmlMimeMail
return $result;
break;
case 'sendmail':
// Get flat representation of headers
foreach ($this->headers as $name => $value) {
$headers[] = $name . ': ' . $this->_encodeHeader($value, $this->build_params['head_charset']);
}
// Encode To:
$headers[] = 'To: ' . $this->_encodeHeader(implode(', ', $recipients), $this->build_params['head_charset']);
// Get return path arg for sendmail command if necessary
$returnPath = '';
if (!empty($this->return_path)) {
$returnPath = '-f' . $this->return_path;
}
$pipe = popen($this->sendmail_path . " " . $returnPath, 'w');
$bytes = fputs($pipe, implode(CRLF, $headers) . CRLF . CRLF . $this->output);
$r = pclose($pipe);
return $r;
break;
case 'smtp':
require_once(dirname(__FILE__) . '/smtp.php');
require_once(dirname(__FILE__) . '/RFC822.php');
......@@ -738,6 +779,11 @@ class htmlMimeMail
$send_params['recipients'] = array_values(array_unique($smtp_recipients));
$send_params['body'] = $this->output;
// Add Notification To
if (isset($this->headers['Disposition-Notification-To'])) {
$send_params['Disposition-Notification-To'] = $this->headers['Disposition-Notification-To'];
}
// Setup return path
if (isset($this->return_path)) {
$send_params['from'] = $this->return_path;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment