title: Cannot declare class PHPMailer\PHPMailer\Exception, because the name is already in use
body: <p>The error:
  <code>Cannot declare class PHPMailer\PHPMailer\Exception, because the name is already in use.</code></p>
  <p>Below is the code being used</p>
  <pre><code> require '/home3/afaflawm/vendor/phpmailer/phpmailer/src/Exception.php';
  require '/home3/afaflawm/vendor/phpmailer/phpmailer/src/PHPMailer.php';
  require '/home3/afaflawm/vendor/phpmailer/phpmailer/src/SMTP.php';
  // Load Composer's autoloader
   require 'vendor/autoload.php';
     use PHPMailer\PHPMailer\PHPMailer;
   use PHPMailer\PHPMailer\SMTP;
   use PHPMailer\PHPMailer\Exception;
     function SendSMTPemail(){
    try {
   $mail = new PHPMailer(true);
    $mail-&gt;SMTPDebug = SMTP::DEBUG_SERVER;  
      $mail-&gt;Host='ssl';
         $mail-&gt;isSMTP();                                            
      $mail-&gt;SMTPAuth   = true;                                   
       $mail-&gt;Username='xy@xy.com'; 
      $mail-&gt;Password='xxxxxxx'; 
         $mail-&gt;setFrom('xy@xy.com');
         $mail-&gt;AddAddress('yz@yz.com');                             // SMTP password
      $mail-&gt;SMTPSecure = 'ssl';
      $mail-&gt;Port       = 465;                                    // TCP port to connect to
      $mail-&gt;addReplyTo('ab@ab.com', 'Information');
          $mail-&gt;isHTML(true);  
     $mail-&gt;Subject = &quot;Appointment Details&quot;;
      $mail-&gt;Body    = &quot;Dear, &lt;br&gt; Please be informed that you have an appointment  tommorow   &lt;br&gt;      Regards &lt;br&gt; &quot;;
      $mail-&gt;AltBody = '';
     if(!$mail-&gt;Send()) {
             echo &quot;Mailer Error: &quot; . $mail-&gt;ErrorInfo;
      } else {
           echo &quot;Message sent!&quot;;
      }
       //echo &quot;success&quot;;
          // $globals['emailstatus'] =true;
          // header(&quot;Location: sendEmail.php&quot;);
     } catch (Exception $e) {
         //echo &quot;fail&quot;;
             // $globals['emailstatus'] =false;
      echo &quot;Message could not be sent.&quot;;
     }
       }
     SendSMTPemail();
  </code></pre>
  <p>If following lines of code are commented,</p>
  <pre><code>   require '/home3/afaflawm/vendor/phpmailer/phpmailer/src/Exception.php';
     require '/home3/afaflawm/vendor/phpmailer/phpmailer/src/PHPMailer.php';
     require '/home3/afaflawm/vendor/phpmailer/phpmailer/src/SMTP.php';
  </code></pre>
  <p>Then it shows the following error:</p>
  <pre><code>   Uncaught Error: Class 'PHPMailer\PHPMailer\SMTP' not found 
  </code></pre>
  <p>If following lines of code are commented,</p>
  <pre><code>   use PHPMailer\PHPMailer\PHPMailer;
     use PHPMailer\PHPMailer\SMTP;
     use PHPMailer\PHPMailer\Exception;
  </code></pre>
  <p>Then it shows the following error:</p>
  <pre><code>     Cannot declare class PHPMailer\PHPMailer\Exception, because the name is already in use 
  </code></pre>
  <p>Following is the directory and its placement:
  <a href="https://i.stack.imgur.com/uHXPs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uHXPs.png" alt="enter image description here" /></a></p>
  <p>I had once used PHPMailer previosuly using Gmail's SMTP which was working fine. Can someone help as to why this error is being displayed though the required files are in the right directory?</p>
  <p><strong>Findings (Edits)</strong>
  I realized there is a PHPMailer folder residing in also wp_content folder as well as wp_includes. I had uploaded PHPMailer  folder to wp_content long time ago when I was working with PHPmailer for gmail. I have multiple copies of this folder in the files. One in the root directory in vendor folder which was created by composer and others in wp_content and wp_includes. wp_includes is strange as I dont know if the composer created or what.. What should I do. I would like to just use the one in wp_content as it was working fine when I had used it using gmail SMTP @Synchro</p>