PHP Class luya\components\Mail

This component is registered on each LUYA instance, how to use: php if (Yii::$app->mail->compose('Subject', 'Message body of the Mail'->adress('[email protected]')->send()) { echo "Mail has been sent!"; } else { echo "Error" : Yii::$app->mail->error; } SMTP debug help: swaks -s HOST -p 587 -ehlo localhost -au AUTH_USER -to TO_ADRESSE -tls
Author: Basil Suter ([email protected])
Inheritance: extends yii\base\Component
显示文件 Open project: luyadev/luya Class Usage Examples

Public Properties

Property Type Description
$altBody alternate text message if email client doesn't support HTML
$debug enable debug output mode 'Data and commands'
$from sender email address
$fromName sender name
$host email server host address
$isSMTP disable if you want to use old PHP sendmail
$layout Define a layout template file which is going to be wrapped around the setBody() content. The file alias will be resolved so an example layout could look as followed: php $layout = '@app/views/maillayout.php'; In your config or any mailer object. As in layouts the content of the mail specific html can be access in the $content variable. The example content of maillayout.php from above could look like this: php

My Company

$password email server password
$port email server port
$smtpSecure Posible values are tls or ssl
$username email server username

Public Methods

Method Description
address ( string $email, string $name = null ) : Mail Add a single address with optional name
addresses ( array $emails ) : Mail Correct spelled alias method for adresses.
adresses ( array $emails ) : Mail Add multiple addresses into the mailer object.
bccAddress ( string $email, string $name = null ) : Mail Add a single BCC address with optional name
bccAddresses ( array $emails ) : Mail Add multiple BCC addresses into the mailer object.
ccAddress ( string $email, string $name = null ) : Mail Add a single CC address with optional name
ccAddresses ( array $emails ) : Mail Add multiple CC addresses into the mailer object.
cleanup ( ) : void Reset the mailer object to null
compose ( string $subject, string $body ) : Mail Compose a new mail message, this will first flush existing mailer objects
getError ( ) : string Get the mailer error info if any.
getMailer ( ) : PHPMailer Getter for the mailer object
send ( ) : boolean Trigger the send event of the mailer
setBody ( string $body ) : Mail Set the HTML body for the mailer message, if a layout is defined the layout will automatically wrapped about the html body.
setSubject ( string $subject ) : Mail Set the mail message subject of the mailer instance
smtpTest ( $verbose )

Protected Methods

Method Description
wrapLayout ( string $content ) Wrap the layout from the $layout propertie and store the passed content as $content variable in the view.

Method Details

address() public method

Add a single address with optional name
public address ( string $email, string $name = null ) : Mail
$email string The email address e.g. [email protected]
$name string The name for the address e.g. John Doe
return Mail

addresses() public method

Correct spelled alias method for adresses.
public addresses ( array $emails ) : Mail
$emails array
return Mail

adresses() public method

If no key is used, the name is going to be ignored, if a string key is available it represents the name. php adresses(['[email protected]', '[email protected]']); or with names php adresses(['John Doe' => '[email protected]', 'Jane Doe' => '[email protected]']);
Since: 1.0.0-beta4
public adresses ( array $emails ) : Mail
$emails array An array with email adresses or name => email paring to use names.
return Mail

bccAddress() public method

Add a single BCC address with optional name
public bccAddress ( string $email, string $name = null ) : Mail
$email string The email address e.g. [email protected]
$name string The name for the address e.g. John Doe
return Mail

bccAddresses() public method

If no key is used, the name is going to be ignored, if a string key is available it represents the name. php bccAddresses(['[email protected]', '[email protected]']); or with names php bccAddresses(['John Doe' => '[email protected]', 'Jane Doe' => '[email protected]']);
Since: 1.0.0-RC2
public bccAddresses ( array $emails ) : Mail
$emails array An array with email addresses or name => email paring to use names.
return Mail

ccAddress() public method

Add a single CC address with optional name
public ccAddress ( string $email, string $name = null ) : Mail
$email string The email address e.g. [email protected]
$name string The name for the address e.g. John Doe
return Mail

ccAddresses() public method

If no key is used, the name is going to be ignored, if a string key is available it represents the name. php ccAddresses(['[email protected]', '[email protected]']); or with names php ccAddresses(['John Doe' => '[email protected]', 'Jane Doe' => '[email protected]']);
Since: 1.0.0-RC2
public ccAddresses ( array $emails ) : Mail
$emails array An array with email addresses or name => email paring to use names.
return Mail

cleanup() public method

Reset the mailer object to null
public cleanup ( ) : void
return void

compose() public method

Compose a new mail message, this will first flush existing mailer objects
public compose ( string $subject, string $body ) : Mail
$subject string The subject of the mail
$body string The HTML body of the mail message.
return Mail

getError() public method

Get the mailer error info if any.
public getError ( ) : string
return string

getMailer() public method

Getter for the mailer object
public getMailer ( ) : PHPMailer
return PHPMailer

send() public method

Trigger the send event of the mailer
public send ( ) : boolean
return boolean

setBody() public method

Set the HTML body for the mailer message, if a layout is defined the layout will automatically wrapped about the html body.
public setBody ( string $body ) : Mail
$body string The HTML body message
return Mail

setSubject() public method

Set the mail message subject of the mailer instance
public setSubject ( string $subject ) : Mail
$subject string The subject message
return Mail

smtpTest() public method

See also: https://github.com/PHPMailer/PHPMailer/blob/master/examples/smtp_check.phps
public smtpTest ( $verbose )

wrapLayout() protected method

Wrap the layout from the $layout propertie and store the passed content as $content variable in the view.
protected wrapLayout ( string $content )
$content string The content to wrapp inside the layout.

Property Details

$altBody public_oe property

alternate text message if email client doesn't support HTML
public $altBody

$debug public_oe property

enable debug output mode 'Data and commands'
public $debug

$from public_oe property

sender email address
public $from

$fromName public_oe property

sender name
public $fromName

$host public_oe property

email server host address
public $host

$isSMTP public_oe property

disable if you want to use old PHP sendmail
public $isSMTP

$layout public_oe property

Define a layout template file which is going to be wrapped around the setBody() content. The file alias will be resolved so an example layout could look as followed: php $layout = '@app/views/maillayout.php'; In your config or any mailer object. As in layouts the content of the mail specific html can be access in the $content variable. The example content of maillayout.php from above could look like this: php

My Company

Since: 1.0.0-beta7
public $layout

$password public_oe property

email server password
public $password

$port public_oe property

email server port
public $port

$smtpSecure public_oe property

Posible values are tls or ssl
public $smtpSecure

$username public_oe property

email server username
public $username