2017-09-05 85 views
1

我知道有很多关于此的线程,但我无法使其工作,我已经尝试了一切! phpmailer下载没有autoload.php,我被卡住了。未被捕获的错误:找不到类'PHPMailer'

请帮助,即使我已经链接了所需的文件,此错误“class”phpmailer'not found“不断出现。 Xampp正在运行。所有的邮件文件都在PHPMailer文件夹内(它包含文件夹src /,里面有5个我链接的文件)。提前致谢!

<!--Contact Starts--> 
     <div class="container contactform center"> 
      <h2 class="text-center wowload fadeInUp"></h2> 
      <div class="row wowload fadeInLeftBig">  
        <div class="col-sm-6 col-sm-offset-3 col-xs-12"> 
        <form method="post" action="index.php"> 
        <input type="text" placeholder="Nombre" name="nombre" required> 
        <input type="email" placeholder="Email" name="email" required> 
        <input type="text" placeholder="Móvil" name="movil" required> 
        <textarea rows="5" placeholder="Mensaje" name="mensaje" required></textarea> 
        <button class="btn btn-danger" type="submit" name="sendBtn"><i class="fa fa-paper-plane"></i> Send</button> 
        </form> 
        </div> 
      </div> 
     </div> 
    </div> 
    <!--Contact Ends--> 

<?php 

if(isset($_POST["sendBtn"])){ 
    require "PHPMailer/src/PHPMailer.php"; 
    require "PHPMailer/src/OAuth.php"; 
    require "PHPMailer/src/SMTP.php"; 
    require "PHPMailer/src/POP3.php"; 
    require "PHPMailer/src/Exception.php"; 

    //Create a new PHPMailer instance 

    $mail = new PHPMailer(); 

    //Tell PHPMailer to use SMTP 

    $mail->isSMTP(); 


    //Enable SMTP debugging 

    // 0 = off (for production use) 

    // 1 = client messages 

    // 2 = client and server messages 

    $mail->SMTPDebug = 2; 



    //Set the hostname of the mail server 

    $mail->Host = 'smtp.gmail.com'; 

    // use 

    // $mail->Host = gethostbyname('smtp.gmail.com'); 

    // if your network does not support SMTP over IPv6 

    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission 

    $mail->Port = 587; 

    //Set the encryption system to use - ssl (deprecated) or tls 

    $mail->SMTPSecure = 'tls'; 

    //Whether to use SMTP authentication 

    $mail->SMTPAuth = true; 

    //Username to use for SMTP authentication - use full email address for gmail 

    $mail->Username = "[email protected]"; 

    //Password to use for SMTP authentication 

    $mail->Password = "xxxxxx"; 

    //Set who the message is to be sent from 

    $mail->setFrom($_POST["email"], $_POST["nombre"]); 

    //Set who the message is to be sent to 

    $mail->addAddress('[email protected]', 'John Doe'); 

    //Set the subject line 

    $mail->Subject = 'PHPMailer GMail SMTP test'; 

    //Read an HTML message body from an external file, convert referenced images to embedded, 

    //convert HTML into a basic plain-text alternative body 

    $mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__)); 



    //Replace the plain text body with one created manually 

    $mail->AltBody = $_POST["mensaje"] . '<br><p Móvil: '.$_POST["movil"].'</p>'; 


    //send the message, check for errors 

    if (!$mail->send()) { 

     echo "Mailer Error: " . $mail->ErrorInfo; 

    } else { 

     echo "Message sent!"; 

    } 
} 
+1

看起来你错过了建议的完整性检查之前要做的其他事情。 https://github.com/PHPMailer/PHPMailer/wiki/Tutorial#first-time也许你没有正确安装 – RiggsFolly

+1

这是'命名空间'问题试试'$ mail = new PHPMailer \ PHPMailer \ PHPMailer();' – cmorrissey

+0

谢谢!工作! – BabyBoy

回答

6

,而不是这样的:

//Create a new PHPMailer instance 
$mail = new PHPMailer(); 

使用本:

//Create a new PHPMailer instance 
$mail = new PHPMailer\PHPMailer\PHPMailer(); 
+1

另一种方法是将PHPMailer的类名导入你的名字空间,例如'使用PHPMailer \ PHPMailer \ PHPMailer; $ mail = new PHPMailer;'这两种方法都在自述文件中详细说明。 – Synchro

0

您必须安装作曲家 要安装见下面的链接中 http://webdevzoom.com/how-to-install-composer-on-windows/

运行这个命令你xampp的项目文件夹在cmd中(本地) “作曲家需要phpmailer/phpmailer”

然后你会在供应商文件夹中获得自动上传文件。 之后,你必须要加上“要求‘供应商/自动上传PHP的。’”你上面的代码..

然后根据要求.. 使用“的PHPMailer/PHPMailer的/ PHPMailer的”使用相应的文件; 使用'phpmailer/phpmailer/Exception';

相关问题