定制 taq/delayedmail 二次开发

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

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

taq/delayedmail

Composer 安装命令:

composer require taq/delayedmail

包简介

Queue email messages in files to send them later

README 文档

README

This is a simple app for sending emails through PHP without blocking sending and waiting answer from the SMTP server. It provides some classes as:

  • Message to compose the message
  • Server to connect to the SMTP server
  • Sender to run and send the queued messages
  • Runner to fire a Sender object

How it works

First we need the server configurations. There is a sample file on the test dir, called delayedmail.ini:

host = smtp.gmail.com
port = 587
user = taq
password = secret
path = /tmp/delayedmailtest

The only different parameter there is the path parameter. This is where the mail files will be stored.

VERY IMPORTANT

If you use two-phase authentication on a Gmail account, sending emails with this library will not work. You need a less secure account to make it works.

Storing messages to send later

The data store used are just regular plain text files. They are stored on the path configured above. On that dir there will be another two subdirs:

  • delivery where the queued messages are.
  • sent, where the messages are moved after Sender send them.
  • error, where the messages are moved if there are some errors on them.

How to use it

Queuing messages

Just include the delayedmail.php on your app, create a new Server object, configure it, compose and queue a new message:

<?php
   include_once "delayedmail.php";

   $server = new DelayedMail\Server("myconfigs.ini");
   $msg    = new DelayedMail\Message();
   $msg->from("taq <eustaquiorangel@gmail.com>")->
           to("Eustaquio Rangel <taq@bluefish.com.br>")->
           cc("Eustaquio Rangel <taq@anotherhost.com>")->
      subject("DelayedMail test!")->
         text("This is just\na test!")->
       attach("taq.jpg");
   $server->push($msg);
?>

If you check the delivery dir now, there will be a file there with the message contents.

You can use arrays on attach and cc.

Running the runner

Just edit the runner.php file with the desired interval and configuration file (usually the same config file as the server) and run it from the command line:

<?php
$dir = dirname(__FILE__);
echo "- loading classes from $dir\n";
include_once "$dir/delayedmail.php";

$sender = new DelayedMail\Sender(5,"delayedmail.ini");
$sender->run();
?>
$ php runner.php
- initializing ...
- checking for files in /tmp/delayedmailtest/delivery ...
- no files found.

Testing

Sending emails

Go to the test directory, configure the delayedmail.ini and test.php files to the configs you want, and run:

$ php test.php

And then check your email app on the addresses you configured.

Code

Run composer update, go to the test directory and run:

$ phpunit .

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL
  • 更新时间: 2013-09-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固