mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKit.git
synced 2026-01-15 00:35:08 +08:00
63 lines
1.4 KiB
PHP
63 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
/**
|
|
* This file is part of LuxAccountX.
|
|
*
|
|
* @link http://124.126.16.154:8888/WebService/LuxAccountX
|
|
* @document https://lux-software.yuque.com/htnx76/vcm2oc
|
|
* @contact dongyun.li@luxcreo.ai
|
|
*/
|
|
|
|
namespace Singularity\HDK\Utils\Service;
|
|
|
|
use Symfony\Component\Mailer\Mailer;
|
|
use Symfony\Component\Mailer\Transport;
|
|
use Symfony\Component\Mime\Address;
|
|
use Symfony\Component\Mime\Email;
|
|
|
|
/**
|
|
* 邮箱验证码
|
|
*/
|
|
class EmailService
|
|
{
|
|
/**
|
|
* @var \Symfony\Component\Mailer\Mailer
|
|
*/
|
|
private Mailer $mailer;
|
|
|
|
public function __construct()
|
|
{
|
|
$dsn = config('common.third_party.email.dsn');
|
|
$transport = Transport::fromDsn($dsn);
|
|
$this->mailer = new Mailer($transport);
|
|
}
|
|
|
|
/**
|
|
* 发送邮件
|
|
*
|
|
* @param string $target
|
|
* @param string $subject
|
|
* @param string $text
|
|
*
|
|
* @return bool
|
|
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
|
*/
|
|
public function sendCode(
|
|
string $target,
|
|
string $subject = '',
|
|
string $text = ''
|
|
): bool {
|
|
$from = config('mailer_sender_name') . ' <' . config('mailer_sender') . '>';
|
|
$email = (new Email())
|
|
->from(Address::create($from))
|
|
->to($target)
|
|
->subject($subject)
|
|
->text($text);
|
|
|
|
$this->mailer->send($email);
|
|
|
|
return true;
|
|
}
|
|
}
|