承接 marikv/mailer 相关项目开发

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

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

marikv/mailer

Composer 安装命令:

composer require marikv/mailer

包简介

Mailer based on swift mailer.

README 文档

README

Mailer is a simple package based on SwiftMailer which allow sending messages with different drivers.

Instalation

You can use the composer package manager to install. Either run:

$ php composer.phar require marikv/mailer "dev-master"

or add:

"marikv/mailer": "dev-master"

to your composer.json file

Configuration

If you use DotEnv package all you have to do is to populate your .env file.

MAIL_DRIVER=smtp // Allow to select transport
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=your_gmail@gmail.com
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=ssl

and start using

$mailer = (new Mailer(
    new Mailer\Transport
))->alwaysFrom('your_email_always_from@gmail.com', 'Your name')
    ->alwaysReplyTo('reply_to@gmailcom', 'Reply name');

If you use other storage repository you can create new Mailer instance and populate with config data from array

$config = array(
    'driver' => 'smtp',
    'host' => 'smtp.gmail.com',
    'port' => 465,
    'username' => 'you_email@gmail.com',
    'password' => 'your_passwd',
    'encryption' => 'ssl'
);

$mailer = (new Mailer\Mailer(
    new Mailer\Transport( $config )
))->alwaysFrom('your_email_always_from@gmail.com', 'Your name')
    ->alwaysReplyTo('reply_to@gmailcom', 'Reply name');

If you want add custom transport all you have to do is to create new transport class which implement TransportAble

class ArrayTransport extends Transport
    implements TransportAble {
    
    /**
     * {@inheritdoc}
     */
    public function send(Swift_Mime_Message $message, &$failedRecipients = null) {
        $this->beforeSendPerformed($message);
        
        // Send your message
    
        return $this->numberOfRecipients($message);
    }
}

And register driver to Transport class.

$tranport = (new Mailer\Transport([
    'driver' => 'my_driver'
]))->extend('my_driver', function($transport) {
    return new ArrayTransport()
});
    
$mailer = (new Mailer($tranport))
->alwaysFrom('your_email_always_from@gmail.com', 'Your name')
    ->alwaysReplyTo('reply_to@gmailcom', 'Reply name');

Usage

You can use directly Mailer and send messages by using ::to('to_email@gmail.com') method

$mailer->to('to_email@gmail.com', 'Subject')
    ->send('This is a test message');

$mailer->to('to_email@gmail.com', 'Subject')->send('Message body', null, function (\Mailer\Message $message) {
    return $message->setFrom('other_from_email@gmail.com');
});

or you can create Mailable classes which require build method

class NewPayment extends \Mailer\Mail
    implements \Mailer\Mailable {

    public function build() {
        $this->text('Body message');
    }
}

$mailer->to(array(
    'to_email@gmail.com'
))->send( new NewPayment('Subject message') );

You can change driver using with method:

$mailer->to('to_email@gmail.com', 'Subject')
    ->with('sendmail')
    ->send('This is a test message');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固