You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

<?php
namespace App\Models;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Mail;
class EmailRecordUser extends SoftDeletesModel
{
protected $casts = ['var_data' => 'json'];
public function emailRecord()
{
return $this->hasOne(EmailRecord::class, 'id', 'email_record_id');
}
/**
* 邮件模版内容替换
* @param $template
* @param $email_record_users
*/
public static function template($template, $var_data)
{
foreach ($var_data as $key => $var) {
$key = trim($key);
$var = trim($var);
$template = str_replace('{' . $key . '}', $var, $template);
}
return $template;
}
/**
* 发送邮件
*/
public static function email($title, $template, $email)
{
Mail::send('email', compact('template'), function ($message) use ($email, $title) {
$message->from(env('MAIL_USERNAME'), '苏州科技商学院');
$message->to($email)->subject($title);
});
return true;
}
}