Class
          Email
              
      
  CakePHP Email class.
This class is used for sending Internet Message Format based on the standard outlined in https://www.rfc-editor.org/rfc/rfc2822.txt
Configuration
Configuration for Email is managed by Email::config() and Email::configTransport(). Email::config() can be used to add or read a configuration profile for Email instances. Once made configuration profiles can be used to re-use across various email messages your application sends.
Deprecated: 4.0.0 This class will be removed in CakePHP 5.0, use {@link \Cake\Mailer\Mailer} instead.
Constants
Property Summary
- 
        $_profile protectedarrayA copy of the configuration profile for this instance. This copy can be modified with Email::profile(). 
- 
        $_transport protectedCake\Mailer\AbstractTransport|nullThe transport instance to use for sending mail. 
- 
        $message protectedCake\Mailer\MessageMessage instance. 
- 
        $messageClass protectedstringMessage class name. 
- 
        $renderer protectedCake\Mailer\Renderer|nullEmail Renderer 
Method Summary
- 
          __call() publicMagic method to forward method class to Email instance. 
- 
          __callStatic() public staticProxy all static method calls (for methods provided by StaticConfigTrait) to Mailer. 
- 
          __clone() publicClone Renderer instance when email object is cloned. 
- 
          __construct() publicConstructor 
- 
          _logDelivery() protectedLog the email message delivery. 
- 
          createFromArray() publicConfigures an email instance object from serialized config. 
- 
          deliver() public staticStatic method to fast create an instance of \Cake\Mailer\Email 
- 
          flatten() protectedConverts given value to string 
- 
          getMessage() publicGet message instance. 
- 
          getProfile() publicGets the configuration profile to use for this instance. 
- 
          getRenderer() publicGet email renderer. 
- 
          getTransport() publicGets the transport. 
- 
          getViewRenderer() publicGets view class for render. 
- 
          getViewVars() publicGets variables to be set on render. 
- 
          jsonSerialize() publicSerializes the email object to a value that can be natively serialized and re-used to clone this email instance. 
- 
          message() publicGet generated message (used by transport classes) 
- 
          render() publicRender email. 
- 
          reset() publicReset all the internal variables to be able to send out a new email. 
- 
          send() publicSend an email using the specified content, template and layout 
- 
          serialize() publicSerializes the Email object. 
- 
          setProfile() publicSets the configuration profile to use for this instance. 
- 
          setRenderer() publicSet email renderer. 
- 
          setTransport() publicSets the transport. 
- 
          setViewRenderer() publicSets view class for render. 
- 
          setViewVars() publicSets variables to be set on render. 
- 
          unserialize() publicUnserializes the Email object. 
- 
          viewBuilder() publicGet view builder. 
Method Detail
__call() ¶ public
__call(string $method, array $args): $this|mixedMagic method to forward method class to Email instance.
Parameters
- 
                string$method
- Method name. 
- 
                array$args
- Method arguments 
Returns
$this|mixed__callStatic() ¶ public static
__callStatic(string $name, array $arguments): mixedProxy all static method calls (for methods provided by StaticConfigTrait) to Mailer.
Parameters
- 
                string$name
- Method name. 
- 
                array$arguments
- Method argument. 
Returns
mixed__clone() ¶ public
__clone(): voidClone Renderer instance when email object is cloned.
Returns
void__construct() ¶ public
__construct(array|string|null $config = null)Constructor
Parameters
- 
                array|string|null$config optional
- Array of configs, or string to load configs from app.php 
_logDelivery() ¶ protected
_logDelivery(array $contents): voidLog the email message delivery.
Parameters
- 
                array$contents
- The content with 'headers' and 'message' keys. 
Returns
voidcreateFromArray() ¶ public
createFromArray(array $config): $thisConfigures an email instance object from serialized config.
Parameters
- 
                array$config
- Email configuration array. 
Returns
$thisConfigured email instance.
deliver() ¶ public static
deliver(string|array|null $to = null, string|null $subject = null, string|array|null $message = null, string|array $config = 'default', bool $send = true): Cake\Mailer\EmailStatic method to fast create an instance of \Cake\Mailer\Email
Parameters
- 
                string|array|null$to optional
- Address to send (see Cake\Mailer\Email::to()). If null, will try to use 'to' from transport config 
- 
                string|null$subject optional
- String of subject or null to use 'subject' from transport config 
- 
                string|array|null$message optional
- String with message or array with variables to be used in render 
- 
                string|array$config optional
- String to use Email delivery profile from app.php or array with configs 
- 
                bool$send optional
- Send the email or just return the instance pre-configured 
Returns
Cake\Mailer\EmailInstance of Cake\Mailer\Email
Throws
InvalidArgumentExceptionflatten() ¶ protected
flatten(string|array $value): stringConverts given value to string
Parameters
- 
                string|array$value
- The value to convert 
Returns
stringgetMessage() ¶ public
getMessage(): Cake\Mailer\MessageGet message instance.
Returns
Cake\Mailer\MessagegetProfile() ¶ public
getProfile(): arrayGets the configuration profile to use for this instance.
Returns
arraygetRenderer() ¶ public
getRenderer(): Cake\Mailer\RendererGet email renderer.
Returns
Cake\Mailer\RenderergetTransport() ¶ public
getTransport(): Cake\Mailer\AbstractTransport|nullGets the transport.
Returns
Cake\Mailer\AbstractTransport|nulljsonSerialize() ¶ public
jsonSerialize(): arraySerializes the email object to a value that can be natively serialized and re-used to clone this email instance.
Returns
arraySerializable array of configuration properties.
Throws
ExceptionWhen a view var object can not be properly serialized.
message() ¶ public
message(string|null $type = null): string|arrayGet generated message (used by transport classes)
Parameters
- 
                string|null$type optional
- Use MESSAGE_* constants or null to return the full message as array 
Returns
string|arrayString if type is given, array if type is null
render() ¶ public
render(string|array|null $content = null): voidRender email.
Parameters
- 
                string|array|null$content optional
- Content array or string 
Returns
voidreset() ¶ public
reset(): $thisReset all the internal variables to be able to send out a new email.
Returns
$thissend() ¶ public
send(string|array|null $content = null): arraySend an email using the specified content, template and layout
Parameters
- 
                string|array|null$content optional
- String with message or array with messages 
Returns
arrayThrows
BadMethodCallExceptionsetProfile() ¶ public
setProfile(string|array $config): $thisSets the configuration profile to use for this instance.
Parameters
- 
                string|array$config
- String with configuration name, or an array with config. 
Returns
$thissetRenderer() ¶ public
setRenderer(Cake\Mailer\Renderer $renderer): $thisSet email renderer.
Parameters
- 
                Cake\Mailer\Renderer$renderer
- Render instance. 
Returns
$thissetTransport() ¶ public
setTransport(string|Cake\Mailer\AbstractTransport $name): $thisSets the transport.
When setting the transport you can either use the name of a configured transport or supply a constructed transport.
Parameters
- 
                string|Cake\Mailer\AbstractTransport$name
- Either the name of a configured transport, or a transport instance. 
Returns
$thisThrows
LogicExceptionWhen the chosen transport lacks a send method.
InvalidArgumentExceptionWhen $name is neither a string nor an object.
setViewRenderer() ¶ public
setViewRenderer(string $viewClass): $thisSets view class for render.
Parameters
- 
                string$viewClass
- View class name. 
Returns
$thissetViewVars() ¶ public
setViewVars(array $viewVars): $thisSets variables to be set on render.
Parameters
- 
                array$viewVars
- Variables to set for view. 
Returns
$thisunserialize() ¶ public
unserialize(string $data): voidUnserializes the Email object.
Parameters
- 
                string$data
- Serialized string. 
Returns
voidviewBuilder() ¶ public
viewBuilder(): Cake\View\ViewBuilderGet view builder.
Returns
Cake\View\ViewBuilder