new pisilinux web sites
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php namespace ZN\Email;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
abstract class DriverMappingAbstract
|
||||
{
|
||||
/**
|
||||
* Send Email
|
||||
*
|
||||
* @param string $to
|
||||
* @param string $subject
|
||||
* @param string $message
|
||||
* @param mixed $headers
|
||||
* @param mixed $settings
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function send($to, $subject, $message, $headers, $settings);
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
<?php namespace ZN\Email\Drivers;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Config;
|
||||
use ZN\Support;
|
||||
use ZN\DateTime\Date;
|
||||
use ZN\Email\DriverMappingAbstract;
|
||||
use ZN\Email\Exception\IMAPConnectException;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class ImapDriver extends DriverMappingAbstract
|
||||
{
|
||||
/**
|
||||
* Connect
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $connect;
|
||||
|
||||
/**
|
||||
* Host
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $host;
|
||||
|
||||
/**
|
||||
* Magic Constructor
|
||||
*/
|
||||
public function __construct(array $config = [])
|
||||
{
|
||||
Support::func('imap_mail');
|
||||
|
||||
$this->connection($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Destructor
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
imap_close($this->connect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Email
|
||||
*
|
||||
* @param string $to
|
||||
* @param string $subject
|
||||
* @param string $message
|
||||
* @param mixed $headers
|
||||
* @param mixed $settings
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function send($to, $subject, $message, $headers = NULL, $settings = NULL)
|
||||
{
|
||||
return imap_mail($to, $subject, $message, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* New
|
||||
*
|
||||
* @param array $config = []
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function new(array $config = [])
|
||||
{
|
||||
return new self($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mail
|
||||
*
|
||||
* @param int $mailId
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function mail(int $mailId)
|
||||
{
|
||||
$overview = imap_fetch_overview($this->connect, $mailId, FT_UID);
|
||||
$structure = imap_fetchstructure($this->connect, $mailId, FT_UID);
|
||||
$header = imap_headerinfo($this->connect, $overview[0]->msgno);
|
||||
|
||||
$from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
|
||||
|
||||
$section = 1;
|
||||
|
||||
if( isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[0]) )
|
||||
{
|
||||
$part = $structure->parts[0];
|
||||
|
||||
if( $part->subtype === 'ALTERNATIVE' )
|
||||
{
|
||||
$section = 1.1;
|
||||
}
|
||||
}
|
||||
|
||||
$message = $this->contentDecoder($part->encoding ?? $structure->encoding, imap_fetchbody($this->connect, $mailId, $section, FT_UID));
|
||||
|
||||
return (object)
|
||||
[
|
||||
'subject' => mb_convert_encoding(imap_utf8($overview[0]->subject), 'ISO-8859-1', 'UTF-8'),
|
||||
'body' => imap_qprint($message),
|
||||
'from' => $this->cc($header->from ?? NULL),
|
||||
'replyTo' => $this->cc($header->reply_to ?? NULL),
|
||||
'cc' => $this->cc($header->cc ?? NULL),
|
||||
'bcc' => $this->cc($header->bcc ?? NULL),
|
||||
'date' => (new Date)->convert($header->Date, 'Y-m-d H:i:s'),
|
||||
'attachments' => $this->attachments($structure->parts ?? NULL, $mailId)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* List
|
||||
*
|
||||
* @param string $flag = 'all'
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list(string $flag = 'all') : array
|
||||
{
|
||||
return imap_search($this->connect, strtoupper($flag), SE_UID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @param scalar $mailId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($mailId) : bool
|
||||
{
|
||||
$return = imap_delete($this->connect, $mailId, FT_UID);
|
||||
|
||||
imap_expunge($this->connect);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move
|
||||
*
|
||||
* @param scalar $mailId
|
||||
* @param string $folder = 'Spam'
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function move($mailId, string $folder = 'Spam') : bool
|
||||
{
|
||||
if( ! in_array($folder, ['Spam', 'Trash', 'Drafts', 'Sent']) )
|
||||
{
|
||||
$folder = imap_utf7_encode($folder);
|
||||
}
|
||||
|
||||
$return = imap_mail_move($this->connect, $mailId, $folder, CP_UID);
|
||||
|
||||
imap_expunge($this->connect);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Folder
|
||||
*
|
||||
* @param string $folder
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function createFolder(string $folder) : bool
|
||||
{
|
||||
return imap_createmailbox($this->connect, $this->utf7FolderEncoder($folder));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Folder
|
||||
*
|
||||
* @param string $folder
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteFolder(string $folder) : bool
|
||||
{
|
||||
return imap_deletemailbox($this->connect, $this->utf7FolderEncoder($folder));
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename Folder
|
||||
*
|
||||
* @param string $folder
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function renameFolder(string $name, string $newName) : bool
|
||||
{
|
||||
$host = '{' . $this->host . '}';
|
||||
|
||||
return imap_renamemailbox($this->connect, $this->utf7FolderEncoder($name), $this->utf7FolderEncoder($newName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Status
|
||||
*
|
||||
* @param scalar $mailId
|
||||
* @param string $status
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function changeStatus($mailId, string $status) : bool
|
||||
{
|
||||
$status = ucfirst(strtolower($status));
|
||||
|
||||
if( in_array($status, ['Unread', 'Unseen']) )
|
||||
{
|
||||
return imap_clearflag_full($this->connect, $mailId, '\\Seen', ST_UID);
|
||||
}
|
||||
|
||||
if( $status === 'Read' )
|
||||
{
|
||||
$status = 'Seen';
|
||||
}
|
||||
|
||||
return imap_setflag_full($this->connect, $mailId, '\\' . $status, ST_UID);
|
||||
}
|
||||
|
||||
public function error() : string
|
||||
{
|
||||
return imap_last_error();
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Utf7 Folder Encoder
|
||||
*/
|
||||
protected function utf7FolderEncoder($folder) : string
|
||||
{
|
||||
return imap_utf7_encode('{' . $this->host . '}' . $folder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected connection
|
||||
*/
|
||||
protected function connection(array $config = [])
|
||||
{
|
||||
if( empty($config) )
|
||||
{
|
||||
$config = Config::default('ZN\Email\EmailDefaultConfiguration')::get('Services', 'email')['imap'];
|
||||
}
|
||||
|
||||
$host = $this->host = $config['host'];
|
||||
$user = $config['user'];
|
||||
$password = $config['password'];
|
||||
$port = ':' . ($config['port'] ?? '993');
|
||||
$flags = '/' . implode('/' , $config['flags']);
|
||||
$mailbox = $config['mailbox'] ?? 'INBOX';
|
||||
|
||||
$connect = '{' . $host . $port . $flags . '}' . $mailbox;
|
||||
|
||||
if( ! $host )
|
||||
{
|
||||
throw new IMAPConnectException;
|
||||
}
|
||||
|
||||
$this->connect = imap_open($connect, $user, $password);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected attachments
|
||||
*/
|
||||
protected function attachments($parts, $mailId)
|
||||
{
|
||||
$attachments = [];
|
||||
|
||||
if( $parts ) foreach( $parts as $key => $part )
|
||||
{
|
||||
$body = imap_fetchbody($this->connect, $mailId, $key + 1, FT_UID);
|
||||
|
||||
$body = $this->contentDecoder($part->encoding, $body);
|
||||
|
||||
if( $body && ! empty($part->dparameters) )
|
||||
{
|
||||
$attachments[] =
|
||||
[
|
||||
'file' => $part->dparameters[0]->value,
|
||||
'content' => $body
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected content decoder
|
||||
*/
|
||||
protected function contentDecoder($encoding, $body)
|
||||
{
|
||||
switch( $encoding )
|
||||
{
|
||||
case 1 : $body = imap_8bit($body) ; break;
|
||||
case 2 : $body = imap_binary($body); break;
|
||||
case 3 : $body = imap_base64($body); break;
|
||||
default: $body = imap_qprint($body);
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected cc
|
||||
*/
|
||||
protected function cc($cc)
|
||||
{
|
||||
$addresses = [];
|
||||
|
||||
if( is_array($cc) )
|
||||
{
|
||||
foreach( $cc as $c )
|
||||
{
|
||||
$addresses[] =
|
||||
[
|
||||
'mail' => $c->mailbox . '@' . $c->host,
|
||||
'name' => iconv_mime_decode($c->personal ?? '')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $addresses;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,415 @@
|
||||
<?php namespace ZN\Email\Drivers;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Email\DriverMappingAbstract;
|
||||
use ZN\Email\Exception\SMTPConnectException;
|
||||
use ZN\Email\Exception\SMTPEmptyHostNameException;
|
||||
use ZN\Email\Exception\SMTPEmptyUserPasswordException;
|
||||
use ZN\Email\Exception\SMTPFailedLoginException;
|
||||
use ZN\Email\Exception\SMTPDataFailureException;
|
||||
use ZN\Email\Exception\SMTPAuthException;
|
||||
use ZN\Email\Exception\SMTPAuthPasswordException;
|
||||
|
||||
#[\AllowDynamicProperties]
|
||||
|
||||
class SmtpDriver extends DriverMappingAbstract
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $lf = "\n";
|
||||
|
||||
/**
|
||||
* Keeps connection
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $connect;
|
||||
|
||||
/**
|
||||
* Keeps config variables
|
||||
*/
|
||||
protected $to,
|
||||
$subject,
|
||||
$body,
|
||||
$header,
|
||||
$host,
|
||||
$user,
|
||||
$password,
|
||||
$from,
|
||||
$port,
|
||||
$encoding,
|
||||
$timeout,
|
||||
$cc,
|
||||
$bcc,
|
||||
$auth,
|
||||
$encode,
|
||||
$keepAlive,
|
||||
$dsn,
|
||||
$tos;
|
||||
|
||||
/**
|
||||
* Magic Constructor
|
||||
*
|
||||
* @param string $to
|
||||
* @param string $subject
|
||||
* @param string $message
|
||||
* @param mixed $headers
|
||||
* @param mixed $settings
|
||||
*/
|
||||
public function __construct($to = '', $subject = '', $body = '', $headers = '', $settings = [])
|
||||
{
|
||||
$this->to = $to;
|
||||
$this->subject = $subject;
|
||||
$this->body = $body;
|
||||
$this->header = $headers;
|
||||
$this->host = $settings['host'] ?? '';
|
||||
$this->user = $settings['user'] ?? '';
|
||||
$this->password = $settings['password'] ?? '';
|
||||
$this->from = $settings['from'] ?? '';
|
||||
$this->port = $settings['port'] ?? 587;
|
||||
$this->encoding = $settings['encoding'] ?? '';
|
||||
$this->timeout = $settings['timeout'] ?? '';
|
||||
$this->cc = $settings['cc'] ?? '';
|
||||
$this->bcc = $settings['bcc'] ?? '';
|
||||
$this->auth = $settings['authLogin'] ?? '';
|
||||
$this->encode = $settings['encode'] ?? '';
|
||||
$this->keepAlive = $settings['keepAlive'] ?? '';
|
||||
$this->dsn = $settings['dsn'] ?? '';
|
||||
$this->tos = $settings['tos'] ?? [];
|
||||
$this->lf = $settings['commandLine'] ?? $this->lf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Email
|
||||
*
|
||||
* @param string $to
|
||||
* @param string $subject
|
||||
* @param string $message
|
||||
* @param mixed $headers
|
||||
* @param mixed $settings
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function send($to, $subject, $message, $headers, $settings)
|
||||
{
|
||||
$smtp = new self($to, $subject, $message, $headers, $settings);
|
||||
|
||||
return $smtp->sendEmail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Email
|
||||
*
|
||||
* @return void|true
|
||||
*/
|
||||
public function sendEmail()
|
||||
{
|
||||
$connect = $this->connect();
|
||||
$sending = $this->sending();
|
||||
|
||||
return $sending;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Connect
|
||||
*/
|
||||
protected function connect()
|
||||
{
|
||||
if( is_resource($this->connect) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->socketSSLConnection($errno, $errstr);
|
||||
|
||||
stream_set_timeout($this->connect, $this->timeout);
|
||||
|
||||
$this->error[] = $this->getData();
|
||||
|
||||
if( $this->encode === 'tls' )
|
||||
{
|
||||
$this->encodeSocketWithTLSMethod(); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return $this->setCommand('hello');
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected encode socket with tls method
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function encodeSocketWithTLSMethod()
|
||||
{
|
||||
$this->setCommand('hello'); $this->setCommand('starttls');
|
||||
|
||||
$crypto = stream_socket_enable_crypto($this->connect, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
|
||||
|
||||
if( $crypto !== true )
|
||||
{
|
||||
throw new SMTPConnectException(NULL, $this->getData());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected socket ssl connection
|
||||
*/
|
||||
protected function socketSSLConnection(&$errno, &$errstr)
|
||||
{
|
||||
$context = stream_context_create
|
||||
([
|
||||
'ssl' =>
|
||||
[
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false
|
||||
]
|
||||
]);
|
||||
|
||||
$ssl = $this->encode === 'ssl' ? 'ssl://' : '';
|
||||
|
||||
$this->connect = stream_socket_client($ssl . $this->host . ":" . $this->port, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $context);
|
||||
|
||||
if( is_resource($this->connect) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected socket ssl without connection
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function socketSSLWithoutConnection(&$errno, &$errstr)
|
||||
{
|
||||
$this->connect = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
|
||||
|
||||
if( ! is_resource($this->connect) )
|
||||
{
|
||||
throw new SMTPConnectException(NULL, $errno.' '.$errstr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Sending
|
||||
*/
|
||||
protected function sending()
|
||||
{
|
||||
if( empty($this->host) )
|
||||
{
|
||||
throw new SMTPEmptyHostNameException; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( ! $this->connect() || ! $this->authLogin() )
|
||||
{
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$this->setCommand('from', $this->from);
|
||||
|
||||
if( ! empty($this->tos) ) foreach( $this->tos as $key => $val )
|
||||
{
|
||||
$this->setCommand('to', $key);
|
||||
}
|
||||
|
||||
if( ! empty($this->cc) ) foreach( $this->cc as $key => $val )
|
||||
{
|
||||
$this->setCommand('to', $key); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( ! empty($this->bcc) ) foreach( $this->bcc as $key => $val )
|
||||
{
|
||||
$this->setCommand('to', $key);
|
||||
}
|
||||
|
||||
$this->setCommand('data');
|
||||
|
||||
$this->setData($this->header.preg_replace('/^\./m', '..$1', $this->body));
|
||||
|
||||
$this->setData('.');
|
||||
|
||||
$this->error[] = $reply = $this->getData();
|
||||
|
||||
if( strpos($reply, '250') !== 0 )
|
||||
{
|
||||
throw new SMTPConnectException(NULL, $reply); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( $this->keepAlive )
|
||||
{
|
||||
$this->setCommand('reset'); // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setCommand('quit');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Auth Login
|
||||
*/
|
||||
protected function authLogin()
|
||||
{
|
||||
if( ! $this->auth )
|
||||
{
|
||||
return true; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( $this->user === '' && $this->password === '' )
|
||||
{
|
||||
throw new SMTPEmptyUserPasswordException; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$this->setData('AUTH LOGIN');
|
||||
|
||||
$reply = $this->getData();
|
||||
|
||||
if( strpos($reply, '503') === 0 )
|
||||
{
|
||||
return true; // @codeCoverageIgnore
|
||||
}
|
||||
elseif( strpos($reply, '334') !== 0 )
|
||||
{
|
||||
throw new SMTPFailedLoginException(NULL, $reply); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$this->setData(base64_encode($this->user));
|
||||
|
||||
$reply = $this->getData();
|
||||
|
||||
if( strpos($reply, '334') !== 0 )
|
||||
{
|
||||
throw new SMTPAuthException(NULL, $reply); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$this->setData(base64_encode($this->password));
|
||||
|
||||
$reply = $this->getData();
|
||||
|
||||
if( strpos($reply, '235') !== 0 )
|
||||
{
|
||||
throw new SMTPAuthPasswordException(NULL, $reply); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Set Command
|
||||
*/
|
||||
protected function setCommand($cmd, $data = '')
|
||||
{
|
||||
switch( $cmd )
|
||||
{
|
||||
case 'starttls' : $this->setData('STARTTLS'); $resp = 220; break;
|
||||
case 'from' : $this->setData('MAIL FROM:<'.$data.'>'); $resp = 250; break;
|
||||
case 'data' : $this->setData('DATA'); $resp = 354; break;
|
||||
case 'reset' : $this->setData('RSET'); $resp = 250; break;
|
||||
case 'quit' : $this->setData('QUIT'); $resp = 221; break;
|
||||
case 'hello' :
|
||||
if( $this->auth || $this->encoding === '8bit' )
|
||||
{
|
||||
$this->setData('EHLO '.$this->hostname() );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setData('HELO '.$this->hostname()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$resp = 250;
|
||||
break;
|
||||
case 'to' :
|
||||
if( $this->dsn )
|
||||
{
|
||||
$this->setData('RCPT TO:<'.$data.'> NOTIFY=SUCCESS,DELAY,FAILURE ORCPT=rfc822;'.$data); // @codeCoverageIgnore
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setData('RCPT TO:<'.$data.'>');
|
||||
}
|
||||
$resp = 250;
|
||||
break;
|
||||
}
|
||||
|
||||
$reply = $this->getData();
|
||||
|
||||
$this->error[] = $cmd.': '.$reply; // @codeCoverageIgnore
|
||||
|
||||
if( (int) substr($reply, 0, 3) !== $resp )
|
||||
{
|
||||
throw new SMTPConnectException(NULL, $reply); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( $cmd === 'quit' )
|
||||
{
|
||||
fclose($this->connect);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Set Data
|
||||
*/
|
||||
protected function setData($data)
|
||||
{
|
||||
$data .= $this->lf;
|
||||
|
||||
for( $index = 0; $index < strlen($data); $index += $result )
|
||||
{
|
||||
$result = fwrite($this->connect, substr($data, $index));
|
||||
|
||||
if( $result === false )
|
||||
{
|
||||
break; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
if( $result === false )
|
||||
{
|
||||
throw new SMTPDataFailureException(NULL, $data); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Get Data
|
||||
*/
|
||||
protected function getData()
|
||||
{
|
||||
$data = '';
|
||||
|
||||
while( $str = fgets($this->connect, 512) )
|
||||
{
|
||||
$data .= $str;
|
||||
|
||||
if( $str[3] === ' ' )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prortected Host Name
|
||||
*/
|
||||
protected function hostname()
|
||||
{
|
||||
return $_SERVER['SERVER_NAME'] ?? '[' . ($_SERVER['SERVER_ADDR'] ?? '127.0.0.1') . ']';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php namespace ZN\Email;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default Configuration
|
||||
*
|
||||
* Enabled when the configuration file can not be accessed.
|
||||
*/
|
||||
class EmailDefaultConfiguration
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Email
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Contains settings related to Email library.
|
||||
|
|
||||
| driver: Email send drivers. [smtp, mail, send, pipe, imap]
|
||||
| smtp: Send settings via SMTP.
|
||||
| general: General e-mail settings.
|
||||
|
|
||||
*/
|
||||
|
||||
public $driver = 'smtp';
|
||||
public $smtp =
|
||||
[
|
||||
'host' => '',
|
||||
'user' => '',
|
||||
'password' => '',
|
||||
'port' => 587,
|
||||
'keepAlive' => false,
|
||||
'timeout' => 10,
|
||||
'encode' => '', # empty, tls, ssl
|
||||
'dsn' => false,
|
||||
'auth' => true
|
||||
];
|
||||
public $imap =
|
||||
[
|
||||
'host' => '',
|
||||
'user' => '',
|
||||
'password' => '',
|
||||
'port' => 993,
|
||||
'flags' => [],
|
||||
'mailbox' => 'INBOX'
|
||||
];
|
||||
public $general =
|
||||
[
|
||||
'senderMail' => '', # Default Sender E-mail Address.
|
||||
'senderName' => '', # Default Sender Name.
|
||||
'priority' => 3, # 1, 2, 3, 4, 5
|
||||
'charset' => 'UTF-8', # Charset Type
|
||||
'contentType' => 'html', # plain, html
|
||||
'multiPart' => 'mixed', # mixed, related, alternative
|
||||
'xMailer' => 'ZN',
|
||||
'encoding' => '8bit', # 8bit, 7bit
|
||||
'mimeVersion' => '1.0', # MIME Version
|
||||
'lf' => "\n", # For Mail Body
|
||||
'cr' => "\n", # For STMP Commands
|
||||
'mailPath' => '/usr/sbin/sendmail' # Default Mail Path
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php namespace ZN\Email;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default Cookie Configuration
|
||||
*
|
||||
* Enabled when the language file can not be accessed.
|
||||
*/
|
||||
class EmailDefaultLanguage
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Email
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The language of the Email library.
|
||||
|
|
||||
*/
|
||||
|
||||
public $en =
|
||||
[
|
||||
'email:noSend' => 'Cannot send mail!',
|
||||
'email:attachmentMissing' => 'Unable to locate the following email attachment: %',
|
||||
'email:attachmentUnreadable' => 'Unable to open this attachment: %',
|
||||
'email:noFrom' => 'Cannot send mail with no "From" header!',
|
||||
'email:noSocket' => 'Unable to open a socket to Sendmail! Please check settings!',
|
||||
'email:exitStatus' => 'Exit status code: %',
|
||||
'email:mimeMessage' => 'This is a multi-part message in MIME format.%Your email application may not support this format.',
|
||||
'email:templateColumnError' => 'The template % parameter does not contain column information! Usage -> table: column',
|
||||
'email:templateValueError' => 'The template % parameter does not contain column value information! Usage -> whereColumn: value'
|
||||
];
|
||||
|
||||
public $tr =
|
||||
[
|
||||
'email:noSend' => 'E-posta gönderilmedi!',
|
||||
'email:attachmentMissing' => 'E-posta eki eksik!',
|
||||
'email:attachmentUnreadable' => 'E-posta eki okunamıyor!',
|
||||
'email:noFrom' => 'Kimden bilgisi belirtmeden e-posta gönderilemez!',
|
||||
'email:noSocket' => 'E-posta gönderimi için bir yuva açılamıyor! Ayarlarınızı kontrol edin!',
|
||||
'email:exitStatus' => 'Çıkış durum kodu: %',
|
||||
'email:mimeMessage' => 'Bu MIME biçiminde çok parçalı mesajdır.%E-posta uygulaması bu formatı desteklemiyor olabilir.',
|
||||
'email:templateColumnError' => 'Şablon % parametresi kolon bilgisi içermiyor! Kullanım -> table:column',
|
||||
'email:templateValueError' => 'Şablon % parametresi kolon değer bilgisi içermiyor! Kullanım -> whereColumn:value'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php namespace ZN\Email\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Ability\Exclusion;
|
||||
|
||||
class BadEmailAddressException extends \InvalidArgumentException
|
||||
{
|
||||
use Exclusion;
|
||||
|
||||
const lang =
|
||||
[
|
||||
'en' => '`%` is an invalid email address!',
|
||||
'tr' => '`%` e-posta adresi geçersizdir!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\Email\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Exception;
|
||||
|
||||
class FailureSendEmailException extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'tr' => 'PHP Sendmail kullanarak e-posta göndermek için açılamıyor! Sunucunuz bu yöntemi kullanarak posta göndermek için yapılandırılmamış olabilir!',
|
||||
'en' => 'Unable to send email using PHP Sendmail! Your server might not be configured to send mail using this method!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php namespace ZN\Email\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Ability\Exclusion;
|
||||
|
||||
class IMAPConnectException extends IOException
|
||||
{
|
||||
use Exclusion;
|
||||
|
||||
const lang =
|
||||
[
|
||||
'en' => 'IMAP connection error!',
|
||||
'tr' => 'IMAP bağlantı hatası!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php namespace ZN\Email\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class IOException extends \Exception
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php namespace ZN\Email\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Ability\Exclusion;
|
||||
|
||||
class InvalidCharsetException extends \InvalidArgumentException
|
||||
{
|
||||
use Exclusion;
|
||||
|
||||
const lang =
|
||||
[
|
||||
'en' => '`%` invalid character set!',
|
||||
'tr' => '`%` geçersiz karakter seti!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php namespace ZN\Email\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Ability\Exclusion;
|
||||
|
||||
class SMTPAuthException extends \InvalidArgumentException
|
||||
{
|
||||
use Exclusion;
|
||||
|
||||
const lang =
|
||||
[
|
||||
'en' => 'Failed to authenticate username! %',
|
||||
'tr' => 'Kullanıcı adı kimliği doğrulanamadı! %'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php namespace ZN\Email\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Ability\Exclusion;
|
||||
|
||||
class SMTPAuthPasswordException extends \InvalidArgumentException
|
||||
{
|
||||
use Exclusion;
|
||||
|
||||
const lang =
|
||||
[
|
||||
'en' => 'Failed to authenticate password! %',
|
||||
'tr' => 'Parola kimlik doğrulaması yapılamadı! %'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php namespace ZN\Email\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Ability\Exclusion;
|
||||
|
||||
class SMTPConnectException extends IOException
|
||||
{
|
||||
use Exclusion;
|
||||
|
||||
const lang =
|
||||
[
|
||||
'en' => 'The following SMTP error was encountered: %',
|
||||
'tr' => 'Aşağıdaki SMTP hatası ile karşılaşıldı: %'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\Email\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Exception;
|
||||
|
||||
class SMTPDataFailureException extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'en' => 'Unable to send data: %',
|
||||
'tr' => 'SMPT Veri göndermek için açılamıyor: %'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php namespace ZN\Email\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Ability\Exclusion;
|
||||
|
||||
class SMTPEmptyHostNameException extends \InvalidArgumentException
|
||||
{
|
||||
use Exclusion;
|
||||
|
||||
const lang =
|
||||
[
|
||||
'en' => 'SMTP Host information is empty!',
|
||||
'tr' => 'SMTP Host bilgisi boş!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php namespace ZN\Email\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Ability\Exclusion;
|
||||
|
||||
class SMTPEmptyUserPasswordException extends \InvalidArgumentException
|
||||
{
|
||||
use Exclusion;
|
||||
|
||||
const lang =
|
||||
[
|
||||
'en' => 'You must assign a SMTP username and password!',
|
||||
'tr' => 'Bir SMTP kullanıcı adı ve şifre atamanız gerekir!'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php namespace ZN\Email\Exception;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Exception;
|
||||
|
||||
class SMTPFailedLoginException extends Exception
|
||||
{
|
||||
const lang =
|
||||
[
|
||||
'en' => 'Failed to send AUTH LOGIN command! %',
|
||||
'tr' => 'AUTH LOGIN komutunu gönderilemedi! %'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,988 @@
|
||||
<?php namespace ZN\Email;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\IS;
|
||||
use ZN\Lang;
|
||||
use ZN\Config;
|
||||
use ZN\Datatype;
|
||||
use ZN\Security;
|
||||
use ZN\Singleton;
|
||||
use ZN\Inclusion;
|
||||
use ZN\Ability\Driver;
|
||||
use ZN\DataTypes\Strings;
|
||||
use ZN\Ability\Information;
|
||||
use ZN\Email\Exception\InvalidCharsetException;
|
||||
use ZN\Email\Exception\BadEmailAddressException;
|
||||
|
||||
#[\AllowDynamicProperties]
|
||||
|
||||
class Sender implements SenderInterface
|
||||
{
|
||||
use Driver, Information;
|
||||
|
||||
/**
|
||||
* Driver Settings
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const driver =
|
||||
[
|
||||
'options' => ['smtp', 'imap'],
|
||||
'namespace' => 'ZN\Email\Drivers',
|
||||
'construct' => 'settings',
|
||||
'config' => 'Services:email',
|
||||
'default' => 'ZN\Email\EmailDefaultConfiguration'
|
||||
];
|
||||
|
||||
/**
|
||||
* Email Settings
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $senderMail = '';
|
||||
protected $senderName = '';
|
||||
protected $charset = 'UTF-8';
|
||||
protected $contentType = 'plain';
|
||||
protected $mailPath = '/usr/sbin/sendmail';
|
||||
protected $lf = "\n";
|
||||
protected $cr = "\n";
|
||||
protected $mimeVersion = '1.0';
|
||||
protected $boundary = '';
|
||||
protected $multiPart = 'mixed';
|
||||
protected $priority = 3;
|
||||
protected $encodingType = '8bit';
|
||||
protected $multiParts = ['related', 'alternative', 'mixed'];
|
||||
protected $xMailer = 'ZN';
|
||||
protected $headers = [];
|
||||
protected $header = '';
|
||||
|
||||
/**
|
||||
* SMTP Settings
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $smtpHost = '';
|
||||
protected $smtpUser = '';
|
||||
protected $smtpPassword = '';
|
||||
protected $smtpEncode = '';
|
||||
protected $smtpPort = 587;
|
||||
protected $smtpTimeout = 10;
|
||||
protected $smtpAuth = true;
|
||||
protected $smtpDsn = false;
|
||||
protected $smtpKeepAlive = false;
|
||||
|
||||
/**
|
||||
* Priority Types
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $priorityTypes =
|
||||
[
|
||||
1 => '1 (Highest)',
|
||||
2 => '2 (High)',
|
||||
3 => '3 (Normal)',
|
||||
4 => '4 (Low)',
|
||||
5 => '5 (Lowest)'
|
||||
];
|
||||
|
||||
/**
|
||||
* Sending Email Settings
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $attachments = [];
|
||||
protected $to = [];
|
||||
protected $replyTo = [];
|
||||
protected $cc;
|
||||
protected $bcc;
|
||||
protected $from;
|
||||
protected $subject;
|
||||
protected $message;
|
||||
|
||||
/**
|
||||
* Keeps lang
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $getLang;
|
||||
|
||||
/**
|
||||
* Protected Lang
|
||||
*/
|
||||
protected function getLang(string $type, ?string $changes = NULL) : string
|
||||
{
|
||||
return str_replace('%', $changes ?? '', $this->getLang[$type]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings
|
||||
*
|
||||
* @param array $settings = NULL
|
||||
*
|
||||
* @param return Sender
|
||||
*/
|
||||
public function settings(?array $settings = NULL) : Sender
|
||||
{
|
||||
$this->getLang = Lang::default('ZN\Email\EmailDefaultLanguage')
|
||||
::select('Services');
|
||||
$config = Config::default('ZN\Email\EmailDefaultConfiguration')
|
||||
::get('Services', 'email');
|
||||
$smtpConfig = $config['smtp'];
|
||||
$generalConfig = $config['general'];
|
||||
|
||||
foreach( $smtpConfig as $key => $val )
|
||||
{
|
||||
$nkey = 'smtp'.ucfirst($key);
|
||||
|
||||
$this->$nkey = $settings[$key] ?? $val;
|
||||
}
|
||||
|
||||
foreach( $generalConfig as $key => $val )
|
||||
{
|
||||
$this->$key = $settings[$key] ?? $val;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets command line.
|
||||
*
|
||||
* @param string $commandLine
|
||||
*
|
||||
* @return Sender
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function cr(string $commandLine) : Sender
|
||||
{
|
||||
$this->cr = in_array($commandLine, ["\r\n", "\r", "\n"]) ? $commandLine : "\n";
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets mail line.
|
||||
*
|
||||
* @param string $mailLine
|
||||
*
|
||||
* @return Sender
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function lf(string $mailLine) : Sender
|
||||
{
|
||||
$this->lf = in_array($mailLine, ["\r\n", "\r", "\n"]) ? $mailLine : "\n";
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Content Tyep
|
||||
*
|
||||
* @param string $type = 'plain' - options[plain|html]
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function contentType(string $type = 'plain') : Sender
|
||||
{
|
||||
$this->contentType = $type === 'plain'
|
||||
? 'plain'
|
||||
: 'html';
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets charset
|
||||
*
|
||||
* @param string $charset
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function charset(string $charset = 'UTF-8') : Sender
|
||||
{
|
||||
if( IS::charset($charset) )
|
||||
{
|
||||
$this->charset = $charset;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidCharsetException(NULL, $charset);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets priority
|
||||
*
|
||||
* @param int count = 3
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function priority(int $count = 3) : Sender
|
||||
{
|
||||
$this->priority = preg_match('/^[1-5]$/', $count)
|
||||
? (int)$count
|
||||
: 3;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Header
|
||||
*
|
||||
* @param string $header
|
||||
* @param string $value
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function addHeader(string $header, string $value) : Sender
|
||||
{
|
||||
$this->headers[$header] = str_replace(["\n", "\r"], '', $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Encoding Type
|
||||
*
|
||||
* @param string $type = '8bit' - options[7bit|8bit]
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function encodingType(string $type = '8bit') : Sender
|
||||
{
|
||||
$this->encodingType = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets multipart
|
||||
*
|
||||
* @param string $multiPart = 'related' - options[related|alternative|mixed]
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function multiPart(string $multiPart = 'related') : Sender
|
||||
{
|
||||
$this->multiPart = $multiPart;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets SMTP Host
|
||||
*
|
||||
* @param string $host
|
||||
*
|
||||
* @return Snder
|
||||
*/
|
||||
public function smtpHost(string $host) : Sender
|
||||
{
|
||||
$this->smtpHost = $host;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets SMTP User
|
||||
*
|
||||
* @param string $user
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function smtpUser(string $user) : Sender
|
||||
{
|
||||
$this->smtpUser = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets SMTP DSN
|
||||
*
|
||||
* @param bool $dsn = true
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function smtpDsn(bool $dsn = true) : Sender
|
||||
{
|
||||
$this->smtpDsn = $dsn;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets SMTP Passowrd
|
||||
*
|
||||
* @param string $pass
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function smtpPassword(string $pass) : Sender
|
||||
{
|
||||
$this->smtpPassword = $pass;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets SMTP Port
|
||||
*
|
||||
* @param int port = 587
|
||||
*
|
||||
* @param Sender
|
||||
*/
|
||||
public function smtpPort(int $port = 587) : Sender
|
||||
{
|
||||
$this->smtpPort = $port;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets SMTP Timeout
|
||||
*
|
||||
* @param int $timeout = 10
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function smtpTimeout(int $timeout = 10) : Sender
|
||||
{
|
||||
$this->smtpTimeout = $timeout;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets SMTP Keep Alive
|
||||
*
|
||||
* @param bool $keepAlive = true
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function smtpKeepAlive(bool $keepAlive = true) : Sender
|
||||
{
|
||||
$this->smtpKeepAlive = $keepAlive;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets SMTP Encode
|
||||
*
|
||||
* @param string $encode
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function smtpEncode(string $encode) : Sender
|
||||
{
|
||||
$this->smtpEncode = $encode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* To
|
||||
*
|
||||
* @param mixed $to
|
||||
* @param string $name = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function to($to, ?string $name = NULL) : Sender
|
||||
{
|
||||
$this->toEmail($to, $name, 'to');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* To / Receiver
|
||||
*
|
||||
* @param mixed $to
|
||||
* @param string $name = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function receiver($to, ?string $name = NULL) : Sender
|
||||
{
|
||||
$this->to($to, $name);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reply To
|
||||
*
|
||||
* @param mixed $to
|
||||
* @param string $name = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function replyTo($replyTo, ?string $name = NULL) : Sender
|
||||
{
|
||||
$this->toEmail($replyTo, $name, 'replyTo');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* CC
|
||||
*
|
||||
* @param mixed $to
|
||||
* @param string $name = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function cc($cc, ?string $name = NULL) : Sender
|
||||
{
|
||||
$this->toEmail($cc, $name, 'cc');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* BCC
|
||||
*
|
||||
* @param mixed $to
|
||||
* @param string $name = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function bcc($bcc, ?string $name = NULL) : Sender
|
||||
{
|
||||
$this->toEmail($bcc, $name, 'bcc');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* From
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $name = NULL
|
||||
* @param string $returnPath = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function from(string $from, ?string $name = NULL, ?string $returnPath = NULL) : Sender
|
||||
{
|
||||
if( ! IS::email($from) )
|
||||
{
|
||||
throw new BadEmailAddressException(NULL, $from);
|
||||
}
|
||||
|
||||
$this->from = $from;
|
||||
$returnPath = $returnPath ?? $from;
|
||||
|
||||
$this->addHeader('From', $name.' <'.$from.'>');
|
||||
$this->addHeader('Return-Path', '<'.$returnPath.'>');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* From / Sender
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $name = NULL
|
||||
* @param string $returnPath = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function sender(string $from, ?string $name = NULL, ?string $returnPath = NULL) : Sender
|
||||
{
|
||||
$this->from($from, $name, $returnPath);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subject
|
||||
*
|
||||
* @param string $subject
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function subject(string $subject) : Sender
|
||||
{
|
||||
$this->subject = $subject;
|
||||
$this->addHeader('Subject', $this->subject);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template
|
||||
*
|
||||
* @param string $table
|
||||
* @param mixed $column
|
||||
* @param array $data
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function template(string $table, $column, array $data = []) : Sender
|
||||
{
|
||||
if( is_array($column) && ($content = Inclusion\Template::use($table, $column, true)) )
|
||||
{
|
||||
$this->message($content); // @codeCoverageIgnore
|
||||
}
|
||||
else if( is_scalar($column) )
|
||||
{
|
||||
$tableEx = explode(':', $table);
|
||||
$columnEx = explode(':', $column);
|
||||
|
||||
$table = $tableEx[0];
|
||||
$column = $tableEx[1] ?? NULL;
|
||||
|
||||
if( $column === NULL )
|
||||
{
|
||||
$this->error[] = $this->getLang('email:templateColumnError', '1.($table)'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$whereColumn = $columnEx[0];
|
||||
$whereValue = $columnEx[1] ?? NULL;
|
||||
|
||||
if( $whereValue === NULL )
|
||||
{
|
||||
$this->error[] = $this->getLang('email:templateValueError', '2.($column)'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if( empty($this->error) )
|
||||
{
|
||||
$content = Singleton::class('ZN\Database\DB')->select($column)->where($whereColumn, $whereValue)->get($table)->value();
|
||||
|
||||
$this->message($this->templateMatch($content, $data));
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template Match
|
||||
*
|
||||
* @param string $content
|
||||
* @param array $data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function templateMatch(string $content, array $data) : string
|
||||
{
|
||||
$newData = array();
|
||||
|
||||
foreach( $data as $key => $val )
|
||||
{
|
||||
$newData[Strings\Trim::middle('{{'.$key.'}}')] = $val;
|
||||
}
|
||||
|
||||
return Security\Html::decode(str_replace(array_keys($newData), array_values($newData), $content));
|
||||
}
|
||||
|
||||
/**
|
||||
* Message
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function message(string $message) : Sender
|
||||
{
|
||||
$this->message = $message;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Message / Content
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function content(string $message) : Sender
|
||||
{
|
||||
$this->message($message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attachment
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $disposition = NULL
|
||||
* @param string $newName = NULL
|
||||
* @param mixed $mime = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function attachment(string $file, ?string $disposition = NULL, ?string $newName = NULL, $mime = NULL) : Sender
|
||||
{
|
||||
if( $newName === NULL )
|
||||
{
|
||||
$newName = Datatype::divide($file, '/', -1);
|
||||
}
|
||||
|
||||
# If mime is not specified, treat the extension as a mime.
|
||||
if( $mime === NULL )
|
||||
{
|
||||
$mime = pathinfo($file, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
# Is it a real mime?
|
||||
if( ! strstr($mime ?? '', '/') )
|
||||
{
|
||||
# Check it out from the list
|
||||
if( $mimes = (Singleton::class('ZN\Helpers\Mime')->mimeTypes[$mime] ?? NULL) )
|
||||
{
|
||||
if( is_array($mimes) )
|
||||
{
|
||||
$mime = $mimes[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$mime = $mimes;
|
||||
}
|
||||
}
|
||||
# Set as invalid if it's not listed
|
||||
else
|
||||
{
|
||||
$mime = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if( empty($mime) )
|
||||
{
|
||||
if( strpos($file, '://') === false && ! file_exists($file) )
|
||||
{
|
||||
$this->error[] = $this->getLang('email:attachmentMissing', $file);
|
||||
}
|
||||
|
||||
if( $fp = @fopen($file, 'rb') )
|
||||
{
|
||||
$fileContent = stream_get_contents($fp);
|
||||
|
||||
fclose($fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error[] = $this->getLang('email:attachmentUnreadable', $file);
|
||||
}
|
||||
}
|
||||
else if( ! $fileContent = file_get_contents($file) )
|
||||
{
|
||||
$this->error[] = $this->getLang('email:attachmentUnreadable', $file); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$this->attachments[] =
|
||||
[
|
||||
'name' => [$file, $newName],
|
||||
'disposition' => $disposition ?? 'attachment',
|
||||
'type' => $mime,
|
||||
'content' => chunk_split(base64_encode($fileContent))
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attachment Content ID
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function attachmentContentId(string $filename)
|
||||
{
|
||||
if( $this->multiPart !== 'related' )
|
||||
{
|
||||
$this->multiPart = 'related';
|
||||
}
|
||||
|
||||
$count = count($this->attachments);
|
||||
|
||||
for( $index = 0; $index < $count; $index++ )
|
||||
{
|
||||
if( $this->attachments[$index]['name'][0] === $filename )
|
||||
{
|
||||
$this->attachments[$index]['contentId'] = uniqid(basename($this->attachments[$index]['name'][0]) . '@');
|
||||
|
||||
return $this->attachments[$index]['contentId'];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send
|
||||
*
|
||||
* @param string $subject = NULL
|
||||
* @param string $message = NULL
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function send(?string $subject = NULL, ?string $message = NULL) : bool
|
||||
{
|
||||
if( ! isset($this->headers['From']) )
|
||||
{
|
||||
if( ! empty($this->senderMail) )
|
||||
{
|
||||
$this->sender($this->senderMail, $this->senderName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ! $this->error[] = $this->getLang('email:noFrom'); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
if( ! empty($subject) ) $this->subject($subject);
|
||||
if( ! empty($message) ) $this->message($message);
|
||||
|
||||
if( ! empty($this->to) ) $this->addHeader('To' , $this->toString($this->to) );
|
||||
if( ! empty($this->replyTo) ) $this->addHeader('Reply-To', $this->toString($this->replyTo));
|
||||
if( ! empty($this->cc) ) $this->addHeader('Cc' , $this->toString($this->cc) );
|
||||
if( ! empty($this->bcc) ) $this->addHeader('Bcc' , $this->toString($this->bcc) );
|
||||
|
||||
$this->buildContent();
|
||||
|
||||
$settings =
|
||||
[
|
||||
'host' => $this->smtpHost,
|
||||
'user' => $this->smtpUser,
|
||||
'password' => $this->smtpPassword,
|
||||
'from' => $this->from,
|
||||
'port' => $this->smtpPort,
|
||||
'encoding' => $this->encodingType,
|
||||
'timeout' => $this->smtpTimeout,
|
||||
'cc' => $this->cc,
|
||||
'bcc' => $this->bcc,
|
||||
'authLogin' => $this->smtpAuth,
|
||||
'encode' => $this->smtpEncode,
|
||||
'keepAlive' => $this->smtpKeepAlive,
|
||||
'dsn' => $this->smtpDsn,
|
||||
'tos' => $this->to,
|
||||
'mailPath' => $this->mailPath,
|
||||
'returnPath' => $this->headers['Return-Path'],
|
||||
'commandLine'=> $this->cr
|
||||
];
|
||||
|
||||
$send = $this->driver->send(key($this->to), $this->subject, $this->message, $this->header, $settings);
|
||||
|
||||
if( empty($send) )
|
||||
{
|
||||
return ! $this->error[] = $this->getLang('email:noSend'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$this->defaultVariables();
|
||||
|
||||
return $send;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Build Headers
|
||||
*/
|
||||
protected function buildHeaders()
|
||||
{
|
||||
$this->addHeader('X-Sender', $this->headers['From']);
|
||||
$this->addHeader('X-Mailer', $this->xMailer);
|
||||
$this->addHeader('X-Priority', $this->priorityTypes[$this->priority]);
|
||||
$this->addHeader('Message-ID', $this->getMessageId());
|
||||
$this->addHeader('Mime-Version', $this->mimeVersion);
|
||||
$this->addHeader('Date', $this->getDate());
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Get Date
|
||||
*/
|
||||
protected function getDate()
|
||||
{
|
||||
$timezone = date('Z');
|
||||
$operator = ( $timezone[0] === '-' ) ? '-' : '+';
|
||||
$timezone = abs($timezone);
|
||||
$timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60;
|
||||
|
||||
return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Mime Message
|
||||
*/
|
||||
protected function mimeMessage()
|
||||
{
|
||||
return $this->getLang('email:mimeMessage', $this->lf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Write Headers
|
||||
*/
|
||||
protected function writeHeaders()
|
||||
{
|
||||
foreach( $this->headers as $key => $val )
|
||||
{
|
||||
$val = trim($val);
|
||||
|
||||
if( ! empty($val) )
|
||||
{
|
||||
$this->header .= $key.': '.$val.$this->lf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Get Message ID
|
||||
*/
|
||||
protected function getMessageId()
|
||||
{
|
||||
$from = str_replace(['>', '<'], '', $this->headers['Return-Path']);
|
||||
|
||||
return '<' . uniqid('') . strstr($from, '@') . '>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected to String
|
||||
*/
|
||||
protected function toString($email)
|
||||
{
|
||||
if( is_array($email) )
|
||||
{
|
||||
$string = '';
|
||||
|
||||
foreach( $email as $key => $val )
|
||||
{
|
||||
if( IS::email($key) )
|
||||
{
|
||||
$string .= "$val <$key>, ";
|
||||
}
|
||||
}
|
||||
|
||||
$email = substr(trim($string), 0, -1);
|
||||
}
|
||||
|
||||
return $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Boundary
|
||||
*/
|
||||
protected function boundary()
|
||||
{
|
||||
$this->boundary = 'BOUNDARY_'.md5(uniqid(time()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Build Content
|
||||
*/
|
||||
protected function buildContent()
|
||||
{
|
||||
$this->buildHeaders();
|
||||
$this->boundary();
|
||||
$this->writeHeaders();
|
||||
|
||||
$body = ''; $header = '';
|
||||
|
||||
if( in_array($this->multiPart, $this->multiParts) && ! empty($this->attachments) )
|
||||
{
|
||||
$header .= 'Content-Type: multipart/'.$this->multiPart.'; boundary="'.$this->boundary.'"';
|
||||
|
||||
$body .= $this->mimeMessage().$this->lf.$this->lf;
|
||||
$body .= '--'.$this->boundary.$this->lf;
|
||||
$body .= 'Content-Type: text/'.$this->contentType.'; charset='.$this->charset.$this->lf;
|
||||
$body .= 'Content-Transfer-Encoding: '.$this->encodingType.$this->lf.$this->lf;
|
||||
$body .= $this->message.$this->lf.$this->lf;
|
||||
|
||||
$attachment = [];
|
||||
|
||||
for( $i = 0, $z = 0; $i < count($this->attachments); $i++ )
|
||||
{
|
||||
$basename = $this->attachments[$i]['name'][1];
|
||||
|
||||
$attachment[$z++] = '--'.$this->boundary.$this->lf.
|
||||
'Content-Type: '.$this->attachments[$i]['type'].'; name="'.$basename.'"'.$this->lf.
|
||||
'Content-Disposition: '.$this->attachments[$i]['disposition'].';'.$this->lf.
|
||||
'Content-Transfer-Encoding: base64'.$this->lf.
|
||||
( empty($this->attachments[$i]['contentId'] )
|
||||
? ''
|
||||
: 'Content-ID: <'.$this->attachments[$i]['contentId'].'>'.$this->lf);
|
||||
|
||||
$attachment[$z++] = $this->attachments[$i]['content'];
|
||||
}
|
||||
|
||||
$body .= implode($this->lf, $attachment).$this->lf.'--'.$this->boundary.'--';
|
||||
}
|
||||
else
|
||||
{
|
||||
$header .= 'Content-Type: text/'.$this->contentType.'; charset='.$this->charset.$this->lf;
|
||||
}
|
||||
|
||||
if( $this->selectedDriverName === 'smtp' )
|
||||
{
|
||||
$this->message = $header.$this->lf.$this->lf.$body.$this->message.$this->lf.$this->lf;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->header = $header.$body; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected To
|
||||
*/
|
||||
protected function toEmail($to, $name, $type = 'to')
|
||||
{
|
||||
if( is_array($to) )
|
||||
{
|
||||
if( ! empty($to) ) foreach( $to as $key => $val )
|
||||
{
|
||||
if( IS::email($key) )
|
||||
{
|
||||
$this->{$type}[$key] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( IS::email($to) )
|
||||
{
|
||||
$this->{$type}[$to] = $name;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BadEmailAddressException(NULL, $to);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected Default Variables
|
||||
*/
|
||||
protected function defaultVariables()
|
||||
{
|
||||
$this->subject = '';
|
||||
$this->message = '';
|
||||
$this->header = '';
|
||||
$this->headers = [];
|
||||
$this->addHeader('Date', $this->getDate());
|
||||
$this->attachments = [];
|
||||
$this->cc = NULL;
|
||||
$this->bcc = NULL;
|
||||
$this->boundary = '';
|
||||
$this->to = [];
|
||||
$this->replyTo = [];
|
||||
$this->from = NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
<?php namespace ZN\Email;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
interface SenderInterface
|
||||
{
|
||||
/**
|
||||
* Sets command line.
|
||||
*
|
||||
* @param string $commandLine
|
||||
*
|
||||
* @return Sender
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function cr(string $commandLine) : Sender;
|
||||
|
||||
/**
|
||||
* Sets mail line.
|
||||
*
|
||||
* @param string $mailLine
|
||||
*
|
||||
* @return Sender
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function lf(string $mailLine) : Sender;
|
||||
|
||||
/**
|
||||
* Settings
|
||||
*
|
||||
* @param array $settings = NULL
|
||||
*
|
||||
* @param return Sender
|
||||
*/
|
||||
public function settings(?array $settings = NULL) : Sender;
|
||||
|
||||
/**
|
||||
* Content Tyep
|
||||
*
|
||||
* @param string $type = 'plain' - options[plain|html]
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function contentType(string $type = 'plain') : Sender;
|
||||
|
||||
/**
|
||||
* Sets charset
|
||||
*
|
||||
* @param string $charset
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function charset(string $charset = 'UTF-8') : Sender;
|
||||
|
||||
/**
|
||||
* Sets priority
|
||||
*
|
||||
* @param int count = 3
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function priority(int $count = 3) : Sender;
|
||||
|
||||
/**
|
||||
* Add Header
|
||||
*
|
||||
* @param string $header
|
||||
* @param string $value
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function addHeader(string $header, string $value) : Sender;
|
||||
|
||||
/**
|
||||
* Sets Encoding Type
|
||||
*
|
||||
* @param string $type = '8bit' - options[7bit|8bit]
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function encodingType(string $type = '8bit') : Sender;
|
||||
|
||||
/**
|
||||
* Sets multipart
|
||||
*
|
||||
* @param string $multiPart = 'related' - options[related|alternative|mixed]
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function multiPart(string $multiPart = 'related') : Sender;
|
||||
|
||||
/**
|
||||
* Sets SMTP Host
|
||||
*
|
||||
* @param string $host
|
||||
*
|
||||
* @return Snder
|
||||
*/
|
||||
public function smtpHost(string $host) : Sender;
|
||||
|
||||
/**
|
||||
* Sets SMTP User
|
||||
*
|
||||
* @param string $user
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function smtpUser(string $user) : Sender;
|
||||
|
||||
/**
|
||||
* Sets SMTP DSN
|
||||
*
|
||||
* @param bool $dsn = true
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function smtpDsn(bool $dsn = true) : Sender;
|
||||
|
||||
/**
|
||||
* Sets SMTP Passowrd
|
||||
*
|
||||
* @param string $pass
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function smtpPassword(string $pass) : Sender;
|
||||
|
||||
/**
|
||||
* Sets SMTP Port
|
||||
*
|
||||
* @param int port = 587
|
||||
*
|
||||
* @param Sender
|
||||
*/
|
||||
public function smtpPort(int $port = 587) : Sender;
|
||||
|
||||
/**
|
||||
* Sets SMTP Timeout
|
||||
*
|
||||
* @param int $timeout = 10
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function smtpTimeout(int $timeout = 10) : Sender;
|
||||
|
||||
/**
|
||||
* Sets SMTP Keep Alive
|
||||
*
|
||||
* @param bool $keepAlive = true
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function smtpKeepAlive(bool $keepAlive = true) : Sender;
|
||||
|
||||
/**
|
||||
* Sets SMTP Encode
|
||||
*
|
||||
* @param string $encode
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function smtpEncode(string $encode) : Sender;
|
||||
|
||||
/**
|
||||
* To
|
||||
*
|
||||
* @param mixed $to
|
||||
* @param string $name = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function to($to, string $name) : Sender;
|
||||
|
||||
/**
|
||||
* To / Receiver
|
||||
*
|
||||
* @param mixed $to
|
||||
* @param string $name = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function receiver($to, string $name) : Sender;
|
||||
|
||||
/**
|
||||
* Reply To
|
||||
*
|
||||
* @param mixed $to
|
||||
* @param string $name = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function replyTo($replyTo, string $name) : Sender;
|
||||
|
||||
|
||||
/**
|
||||
* CC
|
||||
*
|
||||
* @param mixed $to
|
||||
* @param string $name = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function cc($cc, string $name) : Sender;
|
||||
|
||||
/**
|
||||
* BCC
|
||||
*
|
||||
* @param mixed $to
|
||||
* @param string $name = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function bcc($bcc, string $name) : Sender;
|
||||
|
||||
/**
|
||||
* From
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $name = NULL
|
||||
* @param string $returnPath = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function from(string $from, ?string $name = NULL, ?string $returnPath = NULL) : Sender;
|
||||
|
||||
/**
|
||||
* From / Sender
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $name = NULL
|
||||
* @param string $returnPath = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function sender(string $from, ?string $name = NULL, ?string $returnPath = NULL) : Sender;
|
||||
|
||||
/**
|
||||
* Subject
|
||||
*
|
||||
* @param string $subject
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function subject(string $subject) : Sender;
|
||||
|
||||
/**
|
||||
* Template
|
||||
*
|
||||
* @param string $table
|
||||
* @param mixed $column
|
||||
* @param array $data
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function template(string $table, $column, array $data = []) : Sender;
|
||||
|
||||
/**
|
||||
* Template Match
|
||||
*
|
||||
* @param string $content
|
||||
* @param array $data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function templateMatch(string $content, array $data) : string;
|
||||
|
||||
/**
|
||||
* Message
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function message(string $message) : Sender;
|
||||
|
||||
/**
|
||||
* Message / Content
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function content(string $message) : Sender;
|
||||
|
||||
/**
|
||||
* Attachment
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $disposition = NULL
|
||||
* @param string $newName = NULL
|
||||
* @param mixed $mime = NULL
|
||||
*
|
||||
* @return Sender
|
||||
*/
|
||||
public function attachment(string $file, ?string $disposition = NULL, ?string $newName = NULL, $mime = NULL) : Sender;
|
||||
|
||||
/**
|
||||
* Attachment Content ID
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function attachmentContentId(string $filename);
|
||||
|
||||
/**
|
||||
* Send
|
||||
*
|
||||
* @param string $subject = NULL
|
||||
* @param string $message = NULL
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function send(?string $subject = NULL, ?string $message = NULL) : bool;
|
||||
}
|
||||
Reference in New Issue
Block a user