29 public function to($addr, $add =
false) {
30 $this->
addr($addr,
'to', $add);
39 public function cc($addr, $add =
false) {
40 $this->
addr($addr,
'cc', $add);
49 public function bcc($addr, $add =
false) {
50 $this->
addr($addr,
'bcc', $add);
60 public function addr($addr, $type, $add =
false) {
61 $tmp = $this->cfg->get($type);
68 $this->cfg->set($type, $tmp);
82 $prm = array(
'file'=>$prm);
84 if (!array_key_exists(
'file', $prm))
89 if (!array_key_exists(
'name', $prm))
91 if (!array_key_exists(
'type', $prm))
93 $this->attachment[] = $prm;
105 if (!is_array($this->cfg->to))
106 $this->cfg->to = array($this->cfg->to);
107 if (!is_array($this->cfg->cc))
108 $this->cfg->cc = array($this->cfg->cc);
109 if (!is_array($this->cfg->bcc))
110 $this->cfg->bcc = array($this->cfg->bcc);
112 if (empty($this->cfg->serverName))
117 $headers.= $this->
headerLine(
'Message-ID',
'<'.uniqid().
'@'.$this->cfg->serverName.
'>');
118 $headers.= $this->
headerLine(
'Date', date(
"D, d M Y G:i:s O"));
119 $headers.= $this->
headerLine(
'From', $this->
formatAddr(array($this->cfg->from, $this->cfg->fromName)));
121 if (empty($this->cfg->replyTo))
122 $this->cfg->replyTo = $this->cfg->from;
125 $headers.= $this->
headerLine(
'Return-Path', $this->cfg->from);
126 $headers.= $this->
headerLine(
'X-Sender', $this->cfg->from);
127 $headers.= $this->
headerLine(
'X-Priority', $this->cfg->priority);
128 $headers.= $this->
headerLine(
'X-Mailer', $this->cfg->xMailer);
130 if (!empty($this->cfg->confirmReading))
131 $headers.= $this->
headerLine(
'Disposition-Notification-To', $this->
formatAddr($this->cfg->confirmReading));
133 if (!empty($this->cfg->cc))
136 if (!empty($this->cfg->bcc))
139 if (is_array($this->cfg->customHeader))
140 foreach($this->cfg->customHeader as $k=>$v)
143 $headers.= $this->
headerLine(
'MIME-Version',
'1.0');
145 if (empty($this->attachment) && strlen($this->cfg->html) == 0)
146 $message_type =
'simpleText';
148 if (strlen($this->cfg->text) > 0 && strlen($this->cfg->html) > 0
149 && !empty($this->attachment))
150 $message_type =
'altAttach';
151 else if (!empty($this->attachment) > 0)
152 $message_type =
'attach';
154 $message_type =
'alt';
157 switch($message_type) {
159 $headers.= $this->
headerLine(
'Content-Type',
'text/plain; charset='.$this->cfg->charset);
160 $headers.= $this->
headerLine(
'Content-Transfer-Encoding', $this->cfg->encoding);
167 $headers.= $this->
headerLine(
'Content-Type',
'multipart/mixed;'.$this->cfg->crlf.
' boundary="'.$boundaryMix.
'"');
170 $body = $this->
textLine(
'--'.$boundaryMix);
175 foreach($this->attachment as $at) {
176 $body.= $this->
textLine(
'--'.$boundaryMix);
177 $body.= $this->
headerLine(
'Content-Type', $at[
'type'].
'; name="'.$at[
'name'].
'"');
178 $body.= $this->
headerLine(
'Content-Transfer-Encoding', $this->cfg->fileEncoding);
179 $body.= $this->
headerLine(
'Content-Disposition',
'attachment; name="'.$at[
'name'].
'"');
184 $body.= $this->
textLine(
'--'.$boundaryMix.
'--');
187 $body = $this->
getBody($headers);
192 foreach($this->cfg->to as $v)
194 $to = implode(
', ', $addr);
196 $param = $this->cfg->addParam;
197 if ($this->cfg->addParamSender)
198 $param.= $this->cfg->addParamSender.$this->cfg->from.
' '.$param;
199 return mail($to, $this->
encodeHeader($this->cfg->subject), $body, $headers, $param);
209 for($i = 0; $i < $ln; $i++)
222 for($w=$e=
'', $n=0, $l=0, $i=0; $i<$ln; $i++) {
236 $e.=
'='.$this->cfg->crlf;
239 $e.= sprintf(
'=%02X', ord($w));
249 $en = ($l==0 || $l+1>75);
252 if ($o>127 || $o<32 || !strcmp($c,
'='))
258 $e.=
'='.$this->cfg->crlf;
267 $c = sprintf(
'=%02X', $o);
275 $e.=
'='.$this->cfg->crlf;
284 $e.=
'='.$this->cfg->crlf;
285 $e.= sprintf(
'=%02X', ord($w));
301 $text = $this->cfg->text;
303 if ($this->cfg->html) {
304 if (empty($this->cfg->text))
308 $boundary =
'------------'.$this->getBoundary();
311 $headers.= $this->
headerLine(
'Content-Type',
'multipart/alternative;'.$this->cfg->crlf.
' boundary="'.$boundary.
'"');
314 $body.= $this->
headerLine(
'Content-Type',
'multipart/alternative;'.$this->cfg->crlf.
' boundary="'.$boundary.
'"');
320 $body.= $this->
textLine(
'This is a multi-part message in MIME format.');
321 $body.= $this->
textLine(
'--'.$boundary);
323 $body.= $this->
headerLine(
'Content-Type',
'text/plain; charset='.$this->cfg->charset);
325 $body.= $this->
headerLine(
'Content-Transfer-Encoding', $this->cfg->encoding);
330 if ($this->cfg->html) {
332 $body.= $this->
textLine(
'--'.$boundary);
334 $html = $this->cfg->html;
336 $inlineImages =
false;
337 if ($this->cfg->htmlInlineImage) {
339 preg_match_all(
'@src="('.$rootUri.
'|/)(.+)"@siU', $html, $matches);
340 if (!empty($matches)) {
341 $images = array_unique($matches[2]);
342 $inlineImages = array();
344 foreach($images as $img) {
346 $file = WEBROOT.str_replace(
'/',
DS, $img);
347 $cid =
'part'.$i.
'.'.$this->
getBoundary(16).
'@'.$this->cfg->serverName;
348 $inlineImages[] = array(
355 $html = preg_replace(
'@src="('.$rootUri.
'|/)('.$img.
')"@siU',
'src="cid:'.$cid.
'"', $html);
361 if (!empty($inlineImages)) {
362 $boundaryRel =
'------------'.$this->getBoundary();
363 $body.= $this->
headerLine(
'Content-Type',
'multipart/related;'.$this->cfg->crlf.
' boundary="'.$boundaryRel.
'"');
367 $body.= $this->
textLine(
'--'.$boundaryRel);
370 $body.= $this->
headerLine(
'Content-Type',
'text/html; charset='.$this->cfg->charset.
'');
372 $body.= $this->
headerLine(
'Content-Transfer-Encoding', $this->cfg->encoding);
378 if (!empty($inlineImages)) {
379 foreach($inlineImages as $img) {
380 $body.= $this->
textLine(
'--'.$boundaryRel);
381 $body.= $this->
headerLine(
'Content-Type', $img[
'type']);
382 $body.= $this->
headerLine(
'Content-Transfer-Encoding', $this->cfg->fileEncoding);
383 $body.= $this->
headerLine(
'Content-ID',
'<'.$img[
'cid'].
'>');
388 $body.= $this->
textLine(
'--'.$boundaryRel.
'--');
392 $body.=
'--'.$boundary.
'--';
405 protected function encode($val, $encoding=null) {
406 $encoding = is_null($encoding) ? $this->cfg->encoding : $encoding;
409 return chunk_split(base64_encode($val), 72, $this->cfg->crlf);
411 $val = $this->
fixEOL($val);
412 if (substr($val, -(strlen($this->cfg->crlf))) != $this->cfg->crlf)
413 $val.= $this->cfg->crlf;
428 public function wrapText($message, $qp_mode =
false) {
429 $length = $this->cfg->wrapLength;
430 $soft_break = ($qp_mode) ? sprintf(
" =%s", $this->cfg->crlf) : $this->cfg->crlf;
433 $is_utf8 = (strtolower($this->cfg->charset) ==
"utf-8");
435 $message = $this->
fixEOL($message);
436 if (substr($message, -1) == $this->cfg->crlf)
437 $message = substr($message, 0, -1);
439 $line = explode($this->cfg->crlf, $message);
442 for ($i = 0 ;$i < $cpt; $i++) {
443 $line_part = explode(
' ', $line[$i]);
444 $cptLine = count($line_part);
446 for ($e = 0; $e<$cptLine; $e++) {
447 $word = $line_part[$e];
448 if ($qp_mode and (strlen($word) > $length)) {
449 $space_left = $length - strlen($buf) - 1;
451 if ($space_left > 20) {
455 } elseif (substr($word, $len - 1, 1) ==
"=") {
457 } elseif (substr($word, $len - 2, 1) ==
"=") {
460 $part = substr($word, 0, $len);
461 $word = substr($word, $len);
463 $message .= $buf . sprintf(
"=%s", $this->cfg->crlf);
465 $message .= $buf . $soft_break;
469 while (strlen($word) > 0) {
473 } elseif (substr($word, $len - 1, 1) ==
"=") {
475 } elseif (substr($word, $len - 2, 1) ==
"=") {
478 $part = substr($word, 0, $len);
479 $word = substr($word, $len);
481 if (strlen($word) > 0) {
482 $message .= $part . sprintf(
"=%s", $this->cfg->crlf);
489 $buf .= ($e == 0) ? $word : (
' ' . $word);
491 if (strlen($buf) > $length and $buf_o !=
'') {
492 $message .= $buf_o . $soft_break;
497 $message .= $buf . $this->cfg->crlf;
509 $str = str_replace(
"\r\n",
"\n", $str);
510 $str = str_replace(
"\r",
"\n", $str);
511 $str = str_replace(
"\n", $this->cfg->crlf, $str);
524 $foundSplitPos =
false;
526 while (!$foundSplitPos) {
527 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
528 $encodedCharPos = strpos($lastChunk,
"=");
529 if ($encodedCharPos !==
false) {
532 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
537 $maxLength = ($encodedCharPos == 0) ? $maxLength :
538 $maxLength - ($lookBack - $encodedCharPos);
539 $foundSplitPos =
true;
540 } elseif ($dec >= 192) {
542 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
543 $foundSplitPos =
true;
544 } elseif ($dec < 192) {
549 $foundSplitPos =
true;
563 return $this->
textLine($name.
': '.$val);
573 return $val.$this->cfg->crlf;
588 return implode(
', ', $addr);
598 if (is_array($addr)) {
599 if (array_key_exists(1, $addr))
617 if (!preg_match(
'/[\200-\377]/', $val)) {
618 return addcslashes($val,
"\0..\37\177\\\"");
626 $nb = preg_match_all(
'/[^\040\041\043-\133\135-\176]/', $val, $matches);
632 $maxlen = 75 - 7 - strlen($this->cfg->charset) - $maxlen % 4;
633 $encoded = trim(chunk_split(base64_encode($val), $maxlen,
"\n"));
634 $encoded = preg_replace(
'/^(.*)$/m',
' =?'.$this->cfg->charset.
'?B?\\1?=', $encoded);
635 $encoded = trim(str_replace(
"\n", $this->cfg->crlf, $encoded));
644 if (is_array($this->cfg->html))
649 return $this->cfg->get($name);
652 public function __set($name, $val) {
653 $this->cfg->set($name, $val);
wrapText($message, $qp_mode=false)
if(!defined('NYROROOT')) define('NYROROOT' ROOT DS
UTF8CharBoundary($encodedText, $maxLength)
encode($val, $encoding=null)
static render(array $prm)
addr($addr, $type, $add=false)