<?php
namespace XYCms;
use think\facade\Cache;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
class Email{
    public static function init($email,$name,$title,$body)
    {
        $mail = new PHPMailer(true);
        try {
            $mail->CharSet ="UTF-8";
            $mail->SMTPDebug = 0;
            $mail->isSMTP();
            $mail->Host = Cache::get('xy_email.host');
            $mail->SMTPAuth = true;
            $mail->Username = Cache::get('xy_email.username');
            $mail->Password = Cache::get('xy_email.password');
            $mail->SMTPSecure = 'ssl';
            $mail->Port = Cache::get('xy_email.port');
            $mail->setFrom(Cache::get('xy_email.username'), Cache::get('xy_email.fromname'));
            $mail->setLanguage('zh_cn');
            $mail->addAddress($email,$name);
            $mail->isHTML();
            $mail->Subject = $title;
            $mail->Body    = $body;
            $mail->send();
            return true;
        } catch (Exception $e) {
            return $mail->ErrorInfo;
        }
    }
}