56 lines
2 KiB
PHP
56 lines
2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Jobs\Mails;
|
||
|
use App\Jobs\Job;
|
||
|
use App\Models\Mail;
|
||
|
use App\Models\Setting;
|
||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||
|
use PHPMailer\PHPMailer\Exception;
|
||
|
|
||
|
class RecoverPasswortJob extends Job
|
||
|
{
|
||
|
private $mailObject = null;
|
||
|
private $token = null;
|
||
|
/**
|
||
|
* Create a new job instance.
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function __construct(Mail $mailObject, $token)
|
||
|
{
|
||
|
$this->mailObject = $mailObject;
|
||
|
$this->token = $token;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Execute the job.
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function handle()
|
||
|
{
|
||
|
if(Setting::getSettingValue("smtp_active") == false) {
|
||
|
return;
|
||
|
}
|
||
|
$mail = new PHPMailer(true);
|
||
|
$mail->isSMTP();
|
||
|
$mail->Host = Setting::getSettingValue("smtp_host");
|
||
|
$mail->SMTPAuth = Setting::getSettingValue("smtp_smtpAuth");
|
||
|
$mail->Username = Setting::getSettingValue("smtp_username");
|
||
|
$mail->Password = Setting::getSettingValue("smtp_password");
|
||
|
$mail->SMTPSecure = Setting::getSettingValue("smtp_secure");
|
||
|
$mail->Port = Setting::getSettingValue("smtp_port");
|
||
|
$mail->setFrom(Setting::getSettingValue("smtp_from_mail"), Setting::getSettingValue("smtp_from_name"));
|
||
|
$mail->addAddress($this->mailObject->mail);
|
||
|
$bcc = Setting::getSettingValue("smtp_bcc");
|
||
|
if(!empty($bcc)) {
|
||
|
$mail->addBCC($bcc);
|
||
|
}
|
||
|
$mail->isHTML(true);
|
||
|
$mail->Subject = Setting::getSettingValue("name").' Password Recovery';
|
||
|
$mail->Body = 'Hello,<br>to reset your Password click on the following link: <a href="'.Setting::getSettingValue('url').'/gui/passwordReset/'.$this->mailObject->getUser()->id.'/'.$this->token.'">Activate Account</a>';
|
||
|
$mail->AltBody = 'Hello,\r\nto reset your Password click on the following link: '.Setting::getSettingValue('url').'/gui/passwordReset/'.$this->mailObject->getUser()->id.'/'.$this->token;
|
||
|
$mail->send();
|
||
|
}
|
||
|
}
|