55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
||
class Mailer
|
||
{
|
||
private static $instance;
|
||
|
||
private function __construct()
|
||
{
|
||
}
|
||
|
||
// 不可以被克隆
|
||
final public function __clone()
|
||
{
|
||
throw new Exception("RequestContext CANNOT clone! use 'instance' method");
|
||
}
|
||
|
||
public static function instance(){
|
||
if (!isset(self::$instance)) {
|
||
self::$instance = new Mailer();
|
||
}
|
||
|
||
return self::$instance;
|
||
}
|
||
|
||
/**
|
||
* 发送邮件
|
||
*
|
||
* @param string $from 发送邮箱
|
||
* @param string $to 收件邮箱
|
||
* @param string $subject 主题
|
||
* @param string $body 邮件内容,默认使用html
|
||
*
|
||
* @return bool
|
||
*/
|
||
public function sendEmail(string $from, string $to, string $subject, string $body): bool
|
||
{
|
||
if( empty($from) || empty($to) ) {
|
||
return false;
|
||
}
|
||
|
||
$mailer = Yii::$app->mailer->compose();
|
||
$mailer->setFrom($from);
|
||
$mailer->setTo($to);
|
||
$mailer->setSubject($subject);
|
||
$mailer->setHtmlBody($body);
|
||
$status = $mailer->send();
|
||
|
||
return $status;
|
||
}
|
||
|
||
public function ceshi(){
|
||
echo 1111;
|
||
}
|
||
}
|
||
|