some
This commit is contained in:
@ -8,28 +8,31 @@ use PHPMailer\PHPMailer\PHPMailer;
|
||||
class SMTP
|
||||
{
|
||||
public PHPMailer $mail;
|
||||
public function __construct(array $config = [])
|
||||
public function __construct()
|
||||
{
|
||||
$this->mail = new PHPMailer(true);
|
||||
$this->mail->CharSet = 'UTF-8';
|
||||
$this->mail->isSMTP();
|
||||
$this->mail->SMTPAuth = true;
|
||||
$this->mail->SMTPDebug = 0;
|
||||
$this->mail->Host = $config['host'] ?? '';
|
||||
$this->mail->Port = $config['port'] ?? 587;
|
||||
$this->mail->Username = $config['username'] ?? '';
|
||||
$this->mail->Password = $config['password'] ?? '';
|
||||
$this->mail->Host = $_ENV['MAIL_SMTP_HOST'];
|
||||
$this->mail->Port = $_ENV['MAIL_SMTP_PORT'];
|
||||
$this->mail->Username = $_ENV['MAIL_SMTP_USERNAME'];
|
||||
$this->mail->Password = $_ENV['MAIL_SMTP_PASSWORD'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function send(string $address): void
|
||||
public function send_html(array $params)
|
||||
{
|
||||
$this->mail->setFrom($this->mail->Username, $this->mail->Host);
|
||||
$this->mail->addAddress($address);
|
||||
$this->mail->Subject = 'Код подтверждения';
|
||||
$body = '<p><strong>«Hello, world!» </strong></p>';
|
||||
if (!isset($params['address'])){
|
||||
return false;
|
||||
}
|
||||
$this->mail->setFrom($this->mail->Username, $params['from_name'] ?? $this->mail->Host);
|
||||
$this->mail->addAddress($params['address']);
|
||||
$this->mail->Subject = $params['subject'] ?? 'Без темы';
|
||||
$body = $params['body'] ?? 'Нет информации';
|
||||
$this->mail->msgHTML($body);
|
||||
|
||||
$this->mail->send();
|
||||
|
Reference in New Issue
Block a user