PHP Class Tools\Mailer\Email

Inheritance: extends Cake\Mailer\Email, use trait Cake\Log\LogTrait
Exibir arquivo Open project: dereuromark/cakephp-tools Class Usage Examples

Protected Properties

Property Type Description
$_debug boolean | null
$_error string | null
$_log array
$_priority integer | null
$_wrapLength integer | null

Public Methods

Method Description
__construct ( string | null $config = null )
addAttachment ( string $file, string | null $name = null, array $fileInfo = [] ) Add an attachment from file
addBlobAttachment ( string $content, string $filename, string | null $mimeType = null, array $fileInfo = [] ) Add an attachment as blob
addEmbeddedAttachment ( string $file, string | null $name = null, string | null $contentId = null, array $options = [] ) : string | $this Add an inline attachment from file
addEmbeddedBlobAttachment ( string $content, string $filename, string | null $mimeType = null, string | null $contentId = null, array $options = [] ) : string | $this Add an inline attachment as blob
attachments ( mixed | null $attachments = null ) : array | $this Overwrite to allow mimetype detection
getError ( ) : string Returns the error if existent
layout ( string | boolean $layout = false ) Change the layout
priority ( integer | null $priority = null ) : integer | $this Set/Get priority
profile ( mixed $config = null ) : string | null | $this Ovewrite to allow custom enhancements
reset ( ) : void EmailLib::resetAndSet()
send ( string | array | null $message = null ) : boolean Set the body of the mail as we send it.
validates ( ) : boolean Validate if the email has the required fields necessary to make send() work.
wrapLength ( integer | null $length = null ) : integer | $this Set/Get wrapLength

Protected Methods

Method Description
_attachFiles ( string | null $boundary = null ) : array Attach non-embedded files by adding file contents inside boundaries.
_attachInlineFiles ( string | null $boundary = null ) : array Attach inline/embedded files to the message.
_getMime ( string $filename, string $default = 'application/octet-stream' ) : string Try to find mimetype by file extension
_getMimeByExtension ( string $ext, string $default = 'application/octet-stream' ) : mixed
_isEmbeddedAttachment ( string $file, string $name ) : boolean | string Returns if this particular file has already been attached as embedded file with this exact name to prevent the same image to overwrite each other and also to only send this image once.
_isEmbeddedBlobAttachment ( string $content, string $name ) : boolean | string Returns if this particular file has already been attached as embedded file with this exact name to prevent the same image to overwrite each other and also to only send this image once.
_logEmail ( string $level = LogLevel::INFO ) : void
_readFile ( string $path ) : string Read the file contents and return a base64 version of the file contents.
_wrap ( string $message, integer $wrapLength = CakeEmail::LINE_LENGTH_MUST ) : array Fix line length

Method Details

__construct() public method

public __construct ( string | null $config = null )
$config string | null

_attachFiles() protected method

CUSTOM FIX: blob data support
protected _attachFiles ( string | null $boundary = null ) : array
$boundary string | null Boundary to use. If null, will default to $this->_boundary
return array An array of lines to add to the message

_attachInlineFiles() protected method

CUSTOM FIX: blob data support
protected _attachInlineFiles ( string | null $boundary = null ) : array
$boundary string | null Boundary to use. If null, will default to $this->_boundary
return array An array of lines to add to the message

_getMime() protected method

Try to find mimetype by file extension
protected _getMime ( string $filename, string $default = 'application/octet-stream' ) : string
$filename string File name
$default string default MimeType
return string Mimetype (falls back to `application/octet-stream`)

_getMimeByExtension() protected method

protected _getMimeByExtension ( string $ext, string $default = 'application/octet-stream' ) : mixed
$ext string
$default string
return mixed

_isEmbeddedAttachment() protected method

Allows multiple usage of the same embedded image (using the same cid)
protected _isEmbeddedAttachment ( string $file, string $name ) : boolean | string
$file string
$name string
return boolean | string CID of the found file or false if no such attachment can be found

_isEmbeddedBlobAttachment() protected method

Allows multiple usage of the same embedded image (using the same cid)
protected _isEmbeddedBlobAttachment ( string $content, string $name ) : boolean | string
$content string
$name string
return boolean | string CID of the found file or false if no such attachment can be found

_logEmail() protected method

protected _logEmail ( string $level = LogLevel::INFO ) : void
$level string
return void

_readFile() protected method

Overwrite parent to avoid File class and file_exists to false negative existent remove images. Also fixes file_get_contents (used via File class) to close the connection again after getting remote files. So far it would have kept the connection open in HTTP/1.1.
protected _readFile ( string $path ) : string
$path string The absolute path to the file to read.
return string File contents in base64 encoding

_wrap() protected method

Fix line length
protected _wrap ( string $message, integer $wrapLength = CakeEmail::LINE_LENGTH_MUST ) : array
$message string Message to wrap
$wrapLength integer
return array Wrapped message

addAttachment() public method

Add an attachment from file
public addAttachment ( string $file, string | null $name = null, array $fileInfo = [] )
$file string Absolute path
$name string | null
$fileInfo array

addBlobAttachment() public method

Add an attachment as blob
public addBlobAttachment ( string $content, string $filename, string | null $mimeType = null, array $fileInfo = [] )
$content string Blob data
$filename string to attach it
$mimeType string | null (leave it empty to get mimetype from $filename)
$fileInfo array

addEmbeddedAttachment() public method

Options: - mimetype - contentDisposition
public addEmbeddedAttachment ( string $file, string | null $name = null, string | null $contentId = null, array $options = [] ) : string | $this
$file string Absolute path
$name string | null (optional)
$contentId string | null (optional)
$options array Options
return string | $this CID or $this

addEmbeddedBlobAttachment() public method

Options: - contentDisposition
public addEmbeddedBlobAttachment ( string $content, string $filename, string | null $mimeType = null, string | null $contentId = null, array $options = [] ) : string | $this
$content string Blob data
$filename string to attach it
$mimeType string | null (leave it empty to get mimetype from $filename)
$contentId string | null (optional)
$options array Options
return string | $this $contentId or $this

attachments() public method

Overwrite to allow mimetype detection
public attachments ( mixed | null $attachments = null ) : array | $this
$attachments mixed | null
return array | $this

getError() public method

Returns the error if existent
public getError ( ) : string
return string

layout() public method

Change the layout
public layout ( string | boolean $layout = false )
$layout string | boolean Layout to use (or false to use none)

priority() public method

Set/Get priority
public priority ( integer | null $priority = null ) : integer | $this
$priority integer | null 1 (highest) to 5 (lowest)
return integer | $this

profile() public method

Ovewrite to allow custom enhancements
public profile ( mixed $config = null ) : string | null | $this
$config mixed
return string | null | $this

reset() public method

EmailLib::resetAndSet()
public reset ( ) : void
return void

send() public method

Note: the text can be an array, each element will appear as a seperate line in the message body. Do NOT pass a message if you use $this->set() in combination with templates
public send ( string | array | null $message = null ) : boolean
$message string | array | null Message
return boolean Success

validates() public method

Assumes layouting (does not check on content to be present or if view/layout files are missing).
public validates ( ) : boolean
return boolean Success

wrapLength() public method

Set/Get wrapLength
public wrapLength ( integer | null $length = null ) : integer | $this
$length integer | null Must not be more than CakeEmail::LINE_LENGTH_MUST
return integer | $this

Property Details

$_debug protected_oe property

protected bool|null $_debug
return boolean | null

$_error protected_oe property

protected string|null $_error
return string | null

$_log protected_oe property

protected array $_log
return array

$_priority protected_oe property

protected int|null $_priority
return integer | null

$_wrapLength protected_oe property

protected int|null $_wrapLength
return integer | null