Laravel 中的外部类和 PHP 文件 - 找不到类

问题描述 投票:0回答:2

我有两个 php 文件,并且我已经创建了一个名为“ExternalClasses”的文件夹并将该文件添加到该文件夹中。在我的 php 文件中,我添加了这一行:

namespace App\ExternalClasses;

在我的控制器中添加这一行:

use App\ExternalClasses\CCheckMail;

这就是我使用它的方式:

$pricesClass = new CCheckMail(); 
$email2 = ['[email protected]']; 
$prices = $pricesClass->execute ($email2); 
return view('pages.home', compact('prices'));

但它给了我一个错误:

Symfony\组件\调试\异常\FatalThrowableError (E_ERROR) 类“App\ExternalClasses\CCheckMail”未找到

这是我的 php 文件(CCheckMail.php):-

<?php 
namespace App\ExternalClasses;
/*
*   This script was writed by Setec Astronomy - [email protected]
*
*   This script is distributed  under the GPL License
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   http://www.gnu.org/licenses/gpl.txt
*
*/
define ('DEBUG_OK', false);
class CCheckMail
{
    var $timeout = 10;
    var $domain_rules = array ("aol.com", "bigfoot.com", "brain.net.pk", "breathemail.net",
                               "compuserve.com", "dialnet.co.uk", "glocksoft.com", "home.com",
                               "msn.com", "rocketmail.com", "uu.net", "yahoo.com", "yahoo.de");

    function _is_valid_email ($email = "") 
    { return preg_match('/^[.\w-]+@([\w-]+\.)+[a-zA-Z]{2,6}$/', $email); }  

    function _check_domain_rules ($domain = "")
    { return in_array (strtolower ($domain), $this->domain_rules); }

    function execute ($email = "")
    {
        if (!$this->_is_valid_email ($email))
        { return false; }

        $host = substr (strstr ($email, '@'), 1);

        if ($this->_check_domain_rules ($host))
        { return false; }

        $host .= ".";

        if (getmxrr ($host, $mxhosts[0],  $mxhosts[1]) == true) 
        { array_multisort ($mxhosts[1],  $mxhosts[0]); }
        else
        {
            $mxhosts[0] = $host;
            $mxhosts[1] = 10;
        } 
        if (DEBUG_OK) { print_r ($mxhosts); }

        $port = 25;
        $localhost = $_SERVER['HTTP_HOST'];
        $sender = 'info@' . $localhost;

        $result = false;
        $id = 0;
        while (!$result && $id < count ($mxhosts[0]))
        {
            if (function_exists ("fsockopen"))
            {
                if (DEBUG_OK) { print_r ($id . " " . $mxhosts[0][$id]); }
                if ($connection = fsockopen ($mxhosts[0][$id], $port, $errno, $error, $this->timeout))
                {
                    fputs ($connection,"HELO $localhost\r\n"); // 250
                    $data = fgets ($connection,1024);
                    $response = substr ($data,0,1);
                    if (DEBUG_OK) { print_r ($data); }

                    if ($response == '2') // 200, 250 etc.
                    { 
                        fputs ($connection,"MAIL FROM:<$sender>\r\n");
                        $data = fgets($connection,1024);
                        $response = substr ($data,0,1);
                        if (DEBUG_OK) { print_r ($data); }

                        if ($response == '2') // 200, 250 etc.
                        { 
                            fputs ($connection,"RCPT TO:<$email>\r\n");
                            $data = fgets($connection,1024);
                            $response = substr ($data,0,1);
                            if (DEBUG_OK) { print_r ($data); }

                            if ($response == '2') // 200, 250 etc.
                            { 
                                fputs ($connection,"data\r\n");
                                $data = fgets($connection,1024);
                                $response = substr ($data,0,1);
                                if (DEBUG_OK) { print_r ($data); }

                                if ($response == '2') // 200, 250 etc.
                                { $result = true; }
                            }
                        }
                    }

                    fputs ($connection,"QUIT\r\n"); 
                    fclose ($connection);
                    if ($result) { return true; }
                }
            }
            else
            { break; } 
            $id++;
        }  
        return false;
    }
}
?>

第二个php文件:

<?php 
/*
*   This script was writed by Setec Astronomy - [email protected]
*
*   On row 41 of CCheckMail.php substitute the following line
*
*   if (getmxrr ($host, $mxhosts[0],  $mxhosts[1]) == true) 
*
*   with
*
*   if (getmxrr_portable ($host, $mxhosts[0],  $mxhosts[1]) == true) 
*
*   to have a fully working portable (*nix and Windows) CCheckMail class
*
*   This script is distributed  under the GPL License
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   http://www.gnu.org/licenses/gpl.txt
*
*/
function getmxrr_win ($hostname = "", &$mxhosts, &$weight)
{
 $weight = array();
 $mxhosts = array();
 $result = false;


 $command = "nslookup -type=mx " . escapeshellarg ($hostname);
 exec ($command, $result);
 $i = 0;
 while (list ($key, $value) = each ($result)) 
 {
    if (strstr ($value, "mail exchanger")) 
    { $nslookup[$i] = $value; $i++; }
 }

 while (list ($key, $value) = each ($nslookup)) 
 {
    $temp = explode ( " ", $value );
    $mx[$key][0] = substr($temp[3],0,-1);
    $mx[$key][1] = $temp[7];
    $mx[$key][2] = gethostbyname ( $temp[7] );
 }

 array_multisort ($mx);

 foreach ($mx as $value) 
 { 
  $mxhosts[] = $value[1];
  $weight[] = $value[0];
 } 

 $result = count ($mxhosts) > 0;
 return $result;
}

function getmxrr_portable ($hostname = "", &$mxhosts, &$weight)
{
 if (function_exists ("getmxrr"))
 { $result = getmxrr ($hostname, $mxhosts, $weight); }
 else
 { $result = getmxrr_win ($hostname, $mxhosts, $weight); }
 return $result; 
}
?>

php laravel laravel-5 eloquent laravel-controller
2个回答
1
投票

只需在终端中输入

composer dumpautoload -o


0
投票

输入错误,我创建了一个新项目并重做我的编码,它工作正常。

© www.soinside.com 2019 - 2024. All rights reserved.