2017-09-05 29 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';

相關問題