定制 yjballestero/yii2-phpmailer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

yjballestero/yii2-phpmailer

Composer 安装命令:

composer require yjballestero/yii2-phpmailer

包简介

PHPMailer Adapter for Yii2

README 文档

README

Mail service for Yii2 using as transport PHPMailer.

Unlike the standard SwiftMailer, it supports sending using the php mail function.

Requirements

This library uses:

  • PHP 8.0+.
  • Yii2 2.0.39+

Install

It is recommended that you install the PHP Browser library through composer. To do so, run the following command:

composer require yjballestero/yii2-phpmailer

Or add this line into your composer.json file:

"yjballestero/yii2-phpmailer": "dev-master"

Setting

 $config = [
     'components' => [
        'mailer' => [
            'class' => yjballestero\phpmailer\PHPMailerMailer::class,            
            // config \PHPMailer\PHPMailer\PHPMailer
            'transportConfig' => [
                'Mailer'     => 'smtp', //Send using SMTP
                'CharSet'    => CHARSET, //us-ascii, iso-8859-1, utf-8
                'Encoding'   => ENCODING, //7bit, 8bit, base64, binary, quoted-printable
                'Host'       => 'smtp.example.com', //Set the SMTP server to send through
                'Username'   => 'user@example.com', //SMTP username
                'Password'   => 'secret', //SMTP password
                'Port'       => MAIL_PORT, //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
                'SMTPSecure' => SMTP_ENCRYPT, //TLS, SSL
                'SMTPAuth'   => true, //Enable SMTP authentication
            ],
            
            // default message config
            'messageConfig' => [
                'from' => FROM
            ]
        ]
    ]
];

A Simple Example of Use

public function sendEmail() {
    $to = 'test@example.com';
    $title = 'test';
    $subject = 'test email';
    $message = 'Hello world';
    
    $email = Yii::$app->mailer->compose(['content'=>$message, 'title'=>$title])
                              ->setTo($to)
                              ->setSubject($subject);
    if($email->send()){
        return 'Message has been sent';
    }
    return $email->mailer->adapter->ErrorInfo;
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-12