PHP Class AcMailer\Service\MailService

Author: Alejandro Celaya Alastrué
Inheritance: implements AcMailer\Service\MailServiceInterface, implements Zend\EventManager\EventManagerAwareInterface, implements AcMailer\Event\MailListenerAwareInterface
Show file Open project: acelaya/zf2-acmailer Class Usage Examples

Public Methods

Method Description
__construct ( Zend\Mail\Message $message, Zend\Mail\Transport\TransportInterface $transport, Zend\View\Renderer\RendererInterface $renderer ) Creates a new MailService
addAttachment ( string $path, string | null $filename = null )
addAttachments ( array $paths )
attachMailListener ( AcMailer\Event\MailListenerInterface $mailListener, integer $priority = 1 ) : mixed | void Attaches a new MailListenerInterface
detachMailListener ( AcMailer\Event\MailListenerInterface $mailListener ) Detaches provided MailListener
getAttachments ( ) : array Returns the list of attachments
getEventManager ( ) : Zend\EventManager\EventManagerInterface Retrieve the event manager Lazy-loads an EventManager instance if none registered.
getMessage ( ) : Zend\Mail\Message Returns this service's message
getRenderer ( ) : Zend\View\Renderer\RendererInterface Returns the renderer object that will be used to render templates
getTransport ( ) : Zend\Mail\Transport\TransportInterface Returns the transport object that will be used to send the wrapped message
send ( ) : AcMailer\Result\ResultInterface Sends the mail
setAttachments ( array $paths )
setBody ( Zend\Mime\Part | Zend\Mime\Message | string $body, string $charset = null ) Sets the message body
setDefaultLayout ( AcMailer\View\DefaultLayoutInterface $layout = null ) : mixed Sets the default layout to be used with all the templates set when calling setTemplate.
setEventManager ( Zend\EventManager\EventManagerInterface $events ) Inject an EventManager instance
setRenderer ( Zend\View\Renderer\RendererInterface $renderer )
setSubject ( string $subject ) Sets the message subject
setTemplate ( string | Zend\View\Model\ViewModel $template, array $params = [] ) Sets the body of this message from a template
setTransport ( Zend\Mail\Transport\TransportInterface $transport )

Protected Methods

Method Description
attachFiles ( ) Attaches files to the message if any
createMailEvent ( string $name = MailEvent::EVENT_MAIL_PRE_SEND, AcMailer\Result\ResultInterface $result = null ) : AcMailer\Event\MailEvent Creates a new MailEvent object
createMailResultFromException ( Exception $e ) : AcMailer\Result\MailResult Creates a error MailResult from an exception
renderChildren ( Zend\View\Model\ViewModel $model ) Renders template childrens.

Method Details

__construct() public method

Creates a new MailService
public __construct ( Zend\Mail\Message $message, Zend\Mail\Transport\TransportInterface $transport, Zend\View\Renderer\RendererInterface $renderer )
$message Zend\Mail\Message
$transport Zend\Mail\Transport\TransportInterface
$renderer Zend\View\Renderer\RendererInterface Renderer used to render templates, typically a PhpRenderer

addAttachment() public method

public addAttachment ( string $path, string | null $filename = null )
$path string
$filename string | null

addAttachments() public method

public addAttachments ( array $paths )
$paths array

attachFiles() protected method

Attaches files to the message if any
protected attachFiles ( )

attachMailListener() public method

Attaches a new MailListenerInterface
public attachMailListener ( AcMailer\Event\MailListenerInterface $mailListener, integer $priority = 1 ) : mixed | void
$mailListener AcMailer\Event\MailListenerInterface
$priority integer
return mixed | void

createMailEvent() protected method

Creates a new MailEvent object
protected createMailEvent ( string $name = MailEvent::EVENT_MAIL_PRE_SEND, AcMailer\Result\ResultInterface $result = null ) : AcMailer\Event\MailEvent
$name string
$result AcMailer\Result\ResultInterface
return AcMailer\Event\MailEvent

createMailResultFromException() protected method

Creates a error MailResult from an exception
protected createMailResultFromException ( Exception $e ) : AcMailer\Result\MailResult
$e Exception
return AcMailer\Result\MailResult

detachMailListener() public method

Detaches provided MailListener
public detachMailListener ( AcMailer\Event\MailListenerInterface $mailListener )
$mailListener AcMailer\Event\MailListenerInterface

getAttachments() public method

Returns the list of attachments
public getAttachments ( ) : array
return array

getEventManager() public method

Retrieve the event manager Lazy-loads an EventManager instance if none registered.
public getEventManager ( ) : Zend\EventManager\EventManagerInterface
return Zend\EventManager\EventManagerInterface

getMessage() public method

Returns this service's message
See also: AcMailer\Service\MailServiceInterface::getMessage()
public getMessage ( ) : Zend\Mail\Message
return Zend\Mail\Message

getRenderer() public method

Returns the renderer object that will be used to render templates
public getRenderer ( ) : Zend\View\Renderer\RendererInterface
return Zend\View\Renderer\RendererInterface

getTransport() public method

Returns the transport object that will be used to send the wrapped message
public getTransport ( ) : Zend\Mail\Transport\TransportInterface
return Zend\Mail\Transport\TransportInterface

renderChildren() protected method

Inspired on Zend\View\View implementation to recursively render child models
See also: Zend\View\View::renderChildren
protected renderChildren ( Zend\View\Model\ViewModel $model )
$model Zend\View\Model\ViewModel

send() public method

Sends the mail
public send ( ) : AcMailer\Result\ResultInterface
return AcMailer\Result\ResultInterface

setAttachments() public method

public setAttachments ( array $paths )
$paths array

setBody() public method

Sets the message body
See also: AcMailer\Service\MailServiceInterface::setBody()
public setBody ( Zend\Mime\Part | Zend\Mime\Message | string $body, string $charset = null )
$body Zend\Mime\Part | Zend\Mime\Message | string Email body
$charset string

setDefaultLayout() public method

Sets the default layout to be used with all the templates set when calling setTemplate.
public setDefaultLayout ( AcMailer\View\DefaultLayoutInterface $layout = null ) : mixed
$layout AcMailer\View\DefaultLayoutInterface
return mixed

setEventManager() public method

Inject an EventManager instance
public setEventManager ( Zend\EventManager\EventManagerInterface $events )
$events Zend\EventManager\EventManagerInterface

setRenderer() public method

public setRenderer ( Zend\View\Renderer\RendererInterface $renderer )
$renderer Zend\View\Renderer\RendererInterface

setSubject() public method

Sets the message subject
Deprecation: Use $mailService->getMessage()->setSubject() instead
public setSubject ( string $subject )
$subject string The subject of the message

setTemplate() public method

Sets the body of this message from a template
See also: AcMailer\Service\MailServiceInterface::setTemplate()
public setTemplate ( string | Zend\View\Model\ViewModel $template, array $params = [] )
$template string | Zend\View\Model\ViewModel
$params array

setTransport() public method

public setTransport ( Zend\Mail\Transport\TransportInterface $transport )
$transport Zend\Mail\Transport\TransportInterface