kzm/tool-email

v1.0 2020-10-23 02:15 UTC

This package is not auto-updated.

Last update: 2024-09-21 00:49:38 UTC


README

介绍

PHP邮件发送

系列工具composer包之邮件发送。使用的 phpmailer ,包装了下,尽量减少配置。

  1. 只支持 SMTP,默认 smtp.163.com
  2. 邮件内容默认html开启,没有altBody

安装

composer require kzm/tool-email

使用说明

<?php

use ToolEmail\Email;

class Demo
{
    public function index()
    {
     	$config = [
     		'host'	   => 'smtp.163.com', // smtp服务器
     		'port'     => 465, // 端口
     		'username' => 'xx@163.com', // 账号
     		'password' => 'password' // 密码或授权码
     	]; 

     	$model = new Email($config);

		// 发送地址的三种格式
     	// 1. $to = 'aa@qq.com'; 				// 单个发送地址
     	// 2. $to = ['aa@qq.com', 'bb@qq.com']; // 批量发送地址
     	// 3. $to = ['aa@qq.com'
     	//				'to' => ['aa@qq.com', 'bb@qq.com'], // 批量发送地址,这里必须是数组
     	//				'cc' => ['cc@qq.com'], 				// 抄送
     	//				'bcc' => ['cc@qq.com'], 			// 保密抄送
     	//			];

     	$to = 'aa@qq.com';

     	$subject = 'test email';
     	$content = '<h4>这是个内容</h4>';

		// 附件地址 支持批量,传参写成数组就行
     	$file = 'rootpath' . DIRECTORY_SEPARATOR . 'a.png';

     	$res = $model->send($to, $subject, $content, $file);
     	if ($res === true) {
     		return 'send is ok';
     	}

     	return $res;
    }
}