2017-11-25 9 views
-1

私はプロジェクトに取り組んでいます。そして、ユーザーがメールとパスワードを入力した後にメールを送信する必要があります。彼らは電子メールを送信するアカウントのクリックをアクティブにすることができます。しかし、私はPHPMailerを使用するとエラーが発生します。エラーはそのようでした新しいPHPMailerにはPHPMailerAutoload.phpが必要ですか?

Fatal error: Uncaught Error: Class 'PHPMailer\PHPMailer' not found in C:\xampp\htdocs\E-Commerce-New-2\registration.php:20 Stack trace: #0 {main} thrown in C:\xampp\htdocs\E-Commerce-New-2\registration.php on line 20

新しいPHPMailerバージョンでは、PHPMailerAutoload.phpファイルを使用しますか?私は答えがノーだと思う。

私はこのコード$mail = new PHPMailer\PHPMailer();とこのコード$mail = new PHPMailer();を使ってみましたが、誰もまだ働いていません。私は

File Strucure

の下に私のファイル構造を置くそして、ここで私は私のコード行を過ぎです。

<?php 
     session_start(); 
     include("includes/db.php"); 
     include("functions/functions.php"); 
     include('PHPMailer/PHPMailer.php'); 
    ?> 
    <?php 
     // If the values are posted, insert them into the database. 
     if (isset($_POST['email']) && isset($_POST['password'])){ 
      $email = $_POST['email']; 
      $password = $_POST['password']; 

      $verification_key = md5($email); 
      $query = "INSERT INTO `customers` (customer_pass,customer_email,verification_key) VALUES ('$password', '$email','$verification_key')"; 

      $result = mysqli_query($con, $query); 
      if($result){ 

      $mail = new PHPMailer\PHPMailer(); 
      $mail->setFrom('[email protected]'); 
      $mail->addAddress($email,'test'); 
      $mail->Subject = "Verify Your Account"; 
      $mail->isHTML(true); 
      $mail->Body = ' Please verify your email address to activate your account by clicking on this link <br> 
       <a href="http://localhost/E-Commerce-New-2/verify.php?key="'. $verification_key.'>Click Here</a>'; 

       if(!$mail->send()) { 
        $fmsg= 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo; 
       } else { 
        $smsg = 'User Registration successfull. Please Check your email to Activate Account!'; 
       } 
     }else{ 
      $fmsg = "User registration failed"; 
     } 
     } 
    ?> 

誰でも私に提案していただけますか?

+0

一部の人々はあなたが本当にこれを解決するためのちょうど最も小さい量で配置する必要が何らかの理由 –

+0

説明せずに質問を否決 - あなたはdownvotesを取得している理由、それはおそらくですが。 PHPMailerに付属のreadmeを読み、提供されているサンプルに基づいてコードを作成してください。 – Synchro

+0

3時間の努力を費やすことはあまりありませんか?わかった。アドバイスをありがとう –

答えて

1

新しいPHPMailer v6.0 +では、PHPスクリプトの一番上にあるグローバル名前空間にPHPMailerクラスをインポートする必要があります。

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

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

$mail = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->Host = "mail.example.com"; 

$mail->SetFrom("$from", "$from"); 
$mail->AddAddress("$to"); 

$mail->Subject = "$subject"; 
$mail->Body = "$message"; 
$mail->Send(); 
関連する問題