承接 samsher-bentray/yii2-mailer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

samsher-bentray/yii2-mailer

最新稳定版本:v0.0.3

Composer 安装命令:

composer require samsher-bentray/yii2-mailer

包简介

PHP and SMTP Mailer

README 文档

README

PHP and SMTP Mailer in Yii2 with dynamic configuration

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

"samsher-bentray/yii2-mailer": "*"

to the require section of your composer.json file.

Configuration

Once the extension is installed, add following code to your application configuration :

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

            ...

            'email' => 'samsher\mailer\Mail',
            
            ...

    ],
];

Usage

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

public function actionCreate()

    {

        $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,

            ]);

        }

    }

统计信息

  • 总下载量: 657
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2015-11-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固