canyin-project/ybcy/extend/Mailer.php
2024-11-01 16:07:54 +08:00

55 lines
1.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
}
}