定制 kisphp/simple-mail 二次开发

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

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

kisphp/simple-mail

Composer 安装命令:

composer require kisphp/simple-mail

包简介

A quick and simple method to send emails

README 文档

README

Build Status codecov.io

Latest Stable Version Total Downloads License Monthly Downloads

Quick send emails with swift mailer for your website with a very simple implementation. By default is configured to send through google.

Installation

composer require kisphp/simple-mail

Configuration

If you already use composer into your project, then the required libraries will be automatically included. Other way you'll have to include autoloader into your php file:

require_once '/path/to/vendor/autoload.php';

First step you need to do, is to create a Configuration class that will implement Kisphp\Mail\MailConfigInterface;.

<?php

namespace Demo;

use Kisphp\Mail\MailConfigInterface;

class DemoMailConfig implements MailConfigInterface
{
    public function getHost()
    {
        return 'ssl://smtp.gmail.com';
    }

    public function getPort()
    {
        return 465;
    }

    public function getSenderUsername()
    {
        return 'your-email-address@gmail.com';
    }

    public function getSenderPassword()
    {
        return 'your account password';
    }

    public function getMailEncryptionType()
    {
        return null;
    }

    public function getFromEmail()
    {
        return 'no-reply@example.com';
    }

    public function getFromName()
    {
        return 'My website';
    }
}

Next you'll need to create extend AbstractMailerFactory class to use your configuration:

class DemoMailerFactory extends AbstractMailerFactory
{
    /**
     * @return DemoMailConfig
     */
    public function createMailConfig()
    {
        return new DemoMailConfig();
    }
}

And from here you can start to use it:

<?php

$messenger = DemoMailerFactory::createMailer();

// recipients
$recipients = [
    'user_1@example.com' => 'User name 1',
    'user_2@example.com' => 'User name 2',
];

$subject = 'Testing mail';
$htmlMessage = 'this is my <b>message</b> for you';

// compose email
$messenger->createMailMessage($recipients, $subject, $htmlMessage);

// send the email and get the number of how many emails were sent
$emailsSent = $messenger->send();

Change mail transport type

To change the transport type you'll have to extend the createMailTransport method from Messenger class:

<?php

use Kisphp\Mail\Messenger;

class ProjectMessenger extends Messenger
{
    /**
     * @return $this
     */
    protected function createMailTransport()
    {
        $this->transport = \Swift_MailTransport::newInstance();
        
        return $this;
    }
}

class DemoMailerFactory extends AbstractMailerFactory
{
    
    // createMailConfig method here
    
    /**
     * @param MailConfigInterface $config
     *
     * @return MessengerInterface
     */
    public function createMessenger(MailConfigInterface $config)
    {
        return new ProjectMessenger($config);
    }
}

// and load this class in your project
$messenger = new ProjectMessenger($config);

More details can be seen here: SwiftMailer Sending

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-03-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固