Синхронизировал частично с CMS2
This commit is contained in:
parent
6b412f5d6f
commit
f2938b1353
30 changed files with 1447 additions and 1099 deletions
62
src/mail.php
62
src/mail.php
|
|
@ -6,14 +6,14 @@
|
|||
*/
|
||||
class Mail
|
||||
{
|
||||
public $from;
|
||||
public $to;
|
||||
public $subject;
|
||||
public $_from;
|
||||
public $_to;
|
||||
public $_subject;
|
||||
public $content;
|
||||
public $copy;
|
||||
|
||||
private $encoding;
|
||||
private $notify= false;
|
||||
private $_notify = null;
|
||||
|
||||
protected $attachment = array ();
|
||||
protected $uniqid;
|
||||
|
|
@ -22,8 +22,6 @@ class Mail
|
|||
function __construct() {
|
||||
$this->setEncoding("UTF-8");
|
||||
$this->uniqid = strtoupper(uniqid(time())); // Идентефикатор разделителя
|
||||
|
||||
// $this->mime
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -31,7 +29,7 @@ class Mail
|
|||
*/
|
||||
function from($name)
|
||||
{
|
||||
$this->from = $name;
|
||||
$this->_from = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -39,7 +37,7 @@ class Mail
|
|||
*/
|
||||
function to($name) // recipient
|
||||
{
|
||||
$this->to = $name;
|
||||
$this->_to = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -52,7 +50,7 @@ class Mail
|
|||
|
||||
function notify($notify)
|
||||
{
|
||||
$this->notify = $notify;
|
||||
$this->_notify = $notify;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -60,7 +58,7 @@ class Mail
|
|||
*/
|
||||
function subject($subject)
|
||||
{
|
||||
$this->subject = $subject;
|
||||
$this->_subject = $subject;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -70,12 +68,7 @@ class Mail
|
|||
{
|
||||
$this->content = $text;
|
||||
}
|
||||
|
||||
function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Кодировка текста в письме
|
||||
*/
|
||||
|
|
@ -93,11 +86,18 @@ class Mail
|
|||
|
||||
if(file_exists($filename)) { // assert ??
|
||||
$file = fopen($filename, "rb");
|
||||
$data = fread($file, filesize($filename));
|
||||
$this->attachment [] = ($name) ? array($data, $name) : array($data, basename($filename));
|
||||
if (is_resource($file)) {
|
||||
$data = fread($file, filesize($filename));
|
||||
$this->attachment [] = ($name) ? array($data, $name) : array($data, basename($filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавление вложения из строки с указанием имени файла
|
||||
*/
|
||||
|
|
@ -115,7 +115,7 @@ class Mail
|
|||
|
||||
/**
|
||||
* Общий формат тегов MIME
|
||||
* http://tools.ietf.org/html/rfc2045
|
||||
* @see http://tools.ietf.org/html/rfc2045
|
||||
*/
|
||||
function mimeTag($name, $value, array $args = array())
|
||||
{
|
||||
|
|
@ -127,7 +127,7 @@ class Mail
|
|||
|
||||
/**
|
||||
*
|
||||
* http://tools.ietf.org/html/rfc2047
|
||||
* @see http://tools.ietf.org/html/rfc2047
|
||||
*/
|
||||
function encodedWord($text, $encoding = 'B')
|
||||
{
|
||||
|
|
@ -144,16 +144,16 @@ class Mail
|
|||
$message .= $this->mimeTag("Content-Transfer-Encoding", "8bit");
|
||||
$message .= PHP_EOL . $this->content . PHP_EOL . PHP_EOL;
|
||||
|
||||
/**
|
||||
/*
|
||||
* Вложения
|
||||
* http://tools.ietf.org/html/rfc2046#section-5.1.3
|
||||
*/
|
||||
foreach ($this->attachment as $value) {
|
||||
list($data, $name) = $value;
|
||||
$message .= "--" . $this->uniqid . PHP_EOL;
|
||||
$message .= $this->mimeTag("Content-Type", "application/octet-stream", array ('name' => $name));
|
||||
$message .= $this->mimeTag("Content-Type", "application/octet-stream", array ('name' => basename($name)));
|
||||
$message .= $this->mimeTag("Content-Transfer-Encoding", "base64");
|
||||
$message .= $this->mimeTag("Content-Disposition", "attachment", array ('filename' => $name));
|
||||
$message .= $this->mimeTag("Content-Disposition", "attachment", array ('filename' => basename($name)));
|
||||
$message .= PHP_EOL . chunk_split(base64_encode($data)) . PHP_EOL;
|
||||
}
|
||||
|
||||
|
|
@ -166,11 +166,11 @@ class Mail
|
|||
function getHeader()
|
||||
{
|
||||
$head = $this->mimeTag("MIME-Version", "1.0");
|
||||
$head .= $this->mimeTag("From", $this->from);
|
||||
$head .= $this->mimeTag("X-Mailer", "CIS Tool");
|
||||
$head .= $this->mimeTag("Reply-To", $this->from);
|
||||
if ($this->notify) {
|
||||
$head .= $this->mimeTag("Disposition-Notification-To", "\"" . $this->notify . "\" <" . $this->from . ">");
|
||||
$head .= $this->mimeTag("From", $this->_from);
|
||||
$head .= $this->mimeTag("X-Mailer", "CMS Tool");
|
||||
$head .= $this->mimeTag("Reply-To", $this->_from);
|
||||
if (is_string($this->_notify)) {
|
||||
$head .= $this->mimeTag("Disposition-Notification-To", "\"" . $this->_notify . "\" <" . $this->_from . ">");
|
||||
}
|
||||
$head .= $this->mimeTag("Content-Type", "multipart/mixed", array ("boundary" => $this->uniqid));
|
||||
if ($this->copy) {
|
||||
|
|
@ -182,7 +182,7 @@ class Mail
|
|||
|
||||
function getSubject()
|
||||
{
|
||||
return $this->encodedWord($this->subject);
|
||||
return $this->encodedWord($this->_subject);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -190,7 +190,7 @@ class Mail
|
|||
*/
|
||||
function eml()
|
||||
{
|
||||
return "To: " . $this->to . PHP_EOL . "Subject: {$this->getSubject()}" . PHP_EOL . $this->getHeader() . $this->getMessage();
|
||||
return "To: " . $this->_to . PHP_EOL . "Subject: {$this->getSubject()}" . PHP_EOL . $this->getHeader() . $this->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -198,7 +198,7 @@ class Mail
|
|||
*/
|
||||
function send()
|
||||
{
|
||||
$result = mail($this->to, $this->getSubject(), $this->getMessage(), $this->getHeader());
|
||||
$result = mail($this->_to, $this->getSubject(), $this->getMessage(), $this->getHeader());
|
||||
if(! $result) {
|
||||
throw new Exception('Невозможно отправить почту');
|
||||
// require_once "core/path.php";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue