PHP ругается за неправильную инициализацию. В чем проблема?
require_once __DIR__ .'\Components\Notification.php';
require_once __DIR__ .'\..\vendor\autoload.php';
require_once __DIR__ .'\Components\Mail.php';
class DB{
/* @var PDO $db*/
public static $db;
/* @var PDO $dbsite*/
public static $dbsite;
public static function init($dbLink, $dbSiteLink){
static::$db = $dbLink;
static::$dbsite = $dbSiteLink;
}
}
DB::init($db, $dbsite);
Mail::init($mailHost,$mailPort,$mailFrom,$mailFromName,$mailPassword);
Мой файл Mail.php
<?php
class Mail{
private static $mailHost;
private static $mailPort;
private static $mailFrom;
private static $mailFromName;
private static $mailPassword;
public static function init($mailHost, $mailPort, $mailFrom, $mailFromName, $mailPassword){
static::$mailHost = $mailHost;
static::$mailPort = $mailPort;
static::$mailFrom = $mailFrom;
static::$mailFromName = $mailFromName;
static::$mailPassword = $mailPassword;
}
public static function sendMail($to,$subject,$body)
{
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
try {
//Server settings
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = 0;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = static::$mailHost; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = static::$mailFrom; // SMTP username
$mail->Password = static::$mailPassword; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = static::$mailPort; // TCP port to connect to
$mail->Timeout = 5;
//Recipients
$mail->setFrom(static::$mailFrom,static::$mailFromName);
$mail->addAddress($to);
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
return $mail->send();
//return true;
} catch (Exception $e) {
return false;
}
}
}
Ошибка здесь DB::init($db, $dbsite);
Notice: Undefined variable: db in C:\xampp\htdocs\bit-home.ru\account\common_functions.php on line 54
Ошибка здесь Mail::init($mailHost,$mailPort,$mailFrom,$mailFromName,$mailPassword); Notice: Undefined variable: mailHost in Notice: Undefined variable: mailPort in Notice: Undefined variable: mailFrom in Notice: Undefined variable: mailFromName Notice: Undefined variable: mailPassword in Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\xampp\htdocs\bit-home.ru\account\common_functions.php:59 Stack trace: #0 C:\xampp\htdocs\bit-home.ru\account\index.php(14): require_once() #1 {main} thrown in