2017 © Pedro Peláez
 

yii2-extension yii2-mailer

mailer

image

tikaraj21/yii2-mailer

mailer

  • Friday, December 30, 2016
  • by bentraytika
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Mailer

PHP and SMTP Mailer in Yii2 with dynamic configuration, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist tikaraj21/yii2-mailer "*"

or add, (*4)

"tikaraj21/yii2-mailer": "*"

if any problem use "yiisoft/yii2-swiftmailer": "~2.0.5", to the require section of your composer.json file., (*5)

Configuration

Once the extension is installed, add following code to your application configuration :, (*6)

return [
    //....
    'components' => [

            ...

            'email' => 'tikaraj21\mailer\Mail',

            ...

    ],
];

Usage

Once the extension is installed, simply use it in your code by using these codes as following way in the controller:, (*7)

```php public function actionCreate(), (*8)

{

    $model = new Email();



    if ($model->load(Yii::$app->request->post())) {

            /*Starting configuration for smtp or other type*/

            Yii::$app->email->setMailType('SMTP');//aeruement is either 'SMTP' or 'PHPMAIL'

            //Passing arguement for Host setting
            Yii::$app->email->setHost('smtp.gmail.com');// aeruement is 'smtp.gmail.com' for gmail

            //Passing arguement for Username setting
            Yii::$app->email->setUname('some email');

            //Passing arguement for Password setting
            Yii::$app->email->setPassd('password');

            //Passing arguement for Encryption Type setting
            Yii::$app->email->setEncType('ssl');//encryption type must either be 'ssl' or 'tls'


            //Passing arguement for Port setting
            Yii::$app->email->setServerPort('465'); port of gmail server is '465' for 'SSL' and '587' for 'TLS'

            /*Ending configuration for smtp or other type*/
            Yii::$app->email->configSet();//note that email setting is completed only after executing this function

            /*Starting configuration for php mail*/

            //Passing arguement to set from
            Yii::$app->email->setFrom('some email');

            //Passing arguement to set Reply To
            Yii::$app->email->setReplyTo('some email');

            //Passing arguement to set Return Path
            Yii::$app->email->setReturnPath('some email');

            $to = $model->to;

            $subject = $model->subject;

            $message_body = $model->text_body;

            $cc = $model->cc;

            $bcc = $model->bcc;

            /*Assigning the files for attachments*/

            $attachment = UploadedFile::getInstances($model,'attachment');

            Yii::$app->email->SaveAttach($attachment);

            // Syntax Yii::$app->email->SendMail($from,$to,$subject,$message_body,$cc,$bcc,$attachment);
            // It is important that default mail type is PHP mail
            // If we want to use PHP mail ,we can call only the function 
            // "Yii::$app->email->SendMail($from,$to,$subject,$message_body,$cc,$bcc,$attachment);"
            // If we want to use Smtp mail or other type, we can call the function
            // "Yii::$app->email->SendMail($from,$to,$subject,$message_body,$cc,$bcc,$attachment);"
            // only after the six setting for and running Yii::$app->email->configSet();

           if (Yii::$app->email->SendMail($from,$to,$subject,$message_body,$cc,$bcc,$attachment)){

                //deleting the attachment
                Yii::$app->email->DeleteAttach($attachments);
                Yii::$app->session->setFlash('success','Email sent.'); //for for wrong event.
                return $this->redirect(['create']);
            }
            else {
                Yii::$app->session->setFlash('danger','Email send not success.'); //for for wrong event.
                return $this->redirect(['create']);
            }
    }

    else{



        return $this->render('create', [

            'model' => $model,

        ]);

    }

}

The Versions

30/12 2016

dev-master

9999999-dev

mailer

  Sources   Download

Apache-2.0

The Requires

 

by Tika Raj

extension yii2