How to send e-mail from YII2 Application

Hi there, This tutorial will show you how to send emails from the yii2 application. Sending emails from the yii2 application is not a tedious task, in fact, we just need to edit/add the config options in your config file.

Yii2 providing a flexible interface for send emails, however, to send emails we have to use external Email libraries/extensions.

Yii2 by default using yii2-swiftmailer official extension.

Open your config/wep.php file and make the following adjustments to send emails using email function.

Find the following:

This will be under the components parameters in the config array. In advanced YII2 application, the file will be in common/main-local.php by default.

Change the code to this:

useFileTransport must be changed to false and transport is set to use Swift_MailTransport.

See the following link for info on swiftmailer transport types.

Basic usage

After completing above email configurations steps. we can use below code to send emails.

See the following link for info on sending emails.

By Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.

3 replies on “How to send e-mail from YII2 Application”

hi arjun,
nice tutorial.
but i got an issue.
how can i know email destination is exist or not ?
i always get return true after i send the email actually that email is not exist.
please help..

thanks in advance

Leave a Reply

Your email address will not be published. Required fields are marked *