v2.5.2
Giriş yap

PHP MAİLER HATASI FONKSİYON İÇİNDE KULLANMA HATASI

singlestroke
218 defa görüntülendi

Back-end servisi olarak php kullanıyorum şifremi unuttum bölümü için bi help fonksiyonu oluşturdum ve içerisinde
6 haneli yeni bir şifre oluşturup o şifreyide mail ile göndermek
istiyorum ancak bir sorun var HTTP ERROR 500 hatası alıyorum php de bir hata var ama ne bilmiyorum sizce sorun nerede ?

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require '../PHPMailer/src/Exception.php';
require '../PHPMailer/src/PHPMailer.php';
require '../PHPMailer/src/SMTP.php';

require '../src/config.php';


$mailer = new PHPMailer(true);
$authServices->mailer = $mailer;


$authServices = new AuthServices;
$authServices->databaseConn = $databaseConn;

class AuthServices
{
    public $databaseConn;
    public $mailer;

    function help($mail)
    {
       
        $query = $this->databaseConn->query("SELECT mail FROM user Where mail='{$mail}'", PDO::FETCH_ASSOC);
        if ($query->rowCount()) {

            $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            $charactersLength = strlen($characters);
            $newPassword = '';
            for ($i = 0; $i < 6; $i++) {
                $newPassword .= $characters[random_int(0, $charactersLength - 1)];
            }

            $query = $this->databaseConn->prepare("UPDATE user SET pass = :newPass WHERE mail = :mail");
            $update = $query->execute(array("newPass" => $newPassword, "mail" => $mail));
            if ( $update ){

                $this->mailer->isSMTP();                                            //Send using SMTP
                $this->mailer->Host       = 'smtp.gmail.com';                     //Set the SMTP server to send through
                $this->mailer->SMTPAuth   = true;                                   //Enable SMTP authentication
                $this->mailer->Username   = '**************';                     //SMTP username
                $this->mailer->Password   = '**************';                               //SMTP password
                $this->mailer->SMTPSecure = "tls";           //Enable implicit TLS encryption
                $this->mailer->Port       = 587;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
            
                //Recipients
                $this->mailer->setFrom('********', 'Yönetici Sistemi');
                $this->mailer->addAddress($mail, 'Yönetici');     //Add a recipient
            
                //Content
                $this->mailer->isHTML(true);                                  //Set email format to HTML
                $this->mailer->Subject = 'Yeni Yönetici Şifreniz';
                $this->mailer->Body    = 'Şifreniz ile yönetici paneline erişebilirsiniz.'.$newPassword;
                
                if($this->mailer->Send()){
                    return array('result' => true, 'message' => 'Yeni şifreniz gönderildi');
                }else{
                    return array('result' => false, 'message' => 'Mail sunucusunda hata var.');
                }

                $this->mailer->ErrorInfo();
            }
        } else {
            return array('result' => false, 'message' => 'Böyle bir mail kayıtlı değil');
        }
        
    }
}
?>
Cevap yaz
Cevaplar (1)
singlestroke
420 gün önce

Hatayı şu şekilde çözdüm

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require '../PHPMailer/src/Exception.php';
require '../PHPMailer/src/PHPMailer.php';
require '../PHPMailer/src/SMTP.php';

require '../src/config.php';


$mailer = new PHPMailer(true);
$authServices = new AuthServices;


$authServices->mailer = $mailer;
$authServices->databaseConn = $databaseConn;