*
* $x= new Pman_Core_Mailer($opts)
*
- * $opts[
+ * $x= Pman_Core_Mailer(array(
page =>
contents
template
mimetype :
),
......
+ mail_method : (SMTP or SMTPMX)
- ]
+ )
*
* recipents is gathered from the resulting template
* -- eg.
* if the file '
*
*
- * $x->asData(); // returns data needed for notify?? - notify should really
+ * $x->toData(); // returns data needed for notify?? - notify should really
* // just use this to pass around later..
*
* $x->send();
var $templateDir = false;
var $locale = false; // eg. 'en' or 'zh_HK'
+
var $html_locale = false; // eg. 'en' or 'zh_HK'
var $images = array(); // generated list of cid images for sending
var $attachments = false;
+ var $mail_method = 'SMTP';
+
function Pman_Core_Mailer($args) {
foreach($args as $k=>$v) {
// a bit trusting..
$htmltemplate->compile('mail/'. $templateFile.'.body.html');
$htmlbody = $htmltemplate->bufferedOutputObject($content);
+ $this->htmlbody = $htmlbody;
+
// for the html body, we may want to convert the attachments to images.
// var_dump($htmlbody);exit;
- $htmlbody = $this->htmlbodytoCID($htmlbody);
+ if ($this->replaceImages) {
+ $htmlbody = $this->htmlbodytoCID($htmlbody);
+ }
}
return array(
'recipents' => $parts[0],
'headers' => $parts[1],
- 'body' => $parts[2]
+ 'body' => $parts[2],
+ 'mailer' => $this
);
}
function send($email = false)
///$recipents = array($this->email);
$mailOptions = PEAR::getStaticProperty('Mail','options');
//print_R($mailOptions);exit;
- $mail = Mail::factory("SMTP",$mailOptions);
+
+ if ($this->mail_method == 'SMTPMX' && empty($mailOptions['mailname'])) {
+ $pg->jerr("Mail[mailname] is not set - this is required for SMTPMX");
+
+ }
+
+ $mail = Mail::factory($this->mail_method,$mailOptions);
+ if ($this->debug) {
+ $mail->debug = $this->debug;
+ }
+
$email['headers']['Date'] = date('r');
if (PEAR::isError($mail)) {
- $pg->addEvent("COREMAILER-FAIL", false, "mail factory failed");
+ $pg->addEvent("COREMAILER-FAIL", false, "mail factory failed");
return $mail;
'To: ' . ( is_array($rcpts) ? implode(', ', $rcpts) : $rcpts ) .
'Subject: ' . @$email['headers']['Subject']
);
- }
-
+ } else {
+ $pg->addEvent("COREMAILER-FAIL", false, $ret->toString());
+ }
+
return $ret;
}
$cache = ini_get('session.save_path')."/Pman_Core_Mailer-{$user}/" . md5($url);
if (file_exists($cache) and filemtime($cache) > strtotime('NOW - 1 WEEK')) {
- $ret = json_decode($cache);
+ $ret = json_decode(file_get_contents($cache), true);
$ret['file'] = $cache . '.data';
return $ret;
}
$a = new HTTP_Request($url);
$a->sendRequest();
file_put_contents($cache .'.data', $a->getResponseBody());
- print_r($a->getResponseBody());exit;
+
$mt = $a->getResponseHeader('Content-Type');
require_once 'File/MimeType.php';