title: phpmailer Invalid Address Error
body: <p>Code:</p>
  
  <pre><code>&lt;?php
  
      if(isset($_POST['data']) &amp;&amp; !empty($_POST['data']) &amp;&amp; isset($_POST['email']) &amp;&amp; !empty($_POST['email'])) {
      $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);  
  
      var_dump($email);
          $data =  explode(',', $_POST['data']);
  
        mailImages($data);
  
      }
  
  
      function mailImages($data){
          require_once "../PHPMailer_5.2.0/class.phpmailer.php";
  
          $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
  
          try {
            $mail-&gt;CharSet = 'UTF-8';
            $mail-&gt;AddReplyTo('kasper.lassner@peterwolf.agency', 'Colegio Suizo de México');
           // $mail-&gt;AddAddress('******@****.agency','K L');
            //$mail-&gt;AddAddress('"'.$email.'"','');
             $mail-&gt;AddAddress($email,'test');
            $mail-&gt;SetFrom('*******@********.agency', 'Colegio Suizo de México');
            $mail-&gt;Subject = 'CSM Fotos';
            $mail-&gt;AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
            $mail-&gt;MsgHTML('Test message');
  
            foreach($data as $image){
               $mail-&gt;AddAttachment(realpath(dirname(__FILE__)).'/'.str_replace(' ','',$image));
            }
  
  
            $mail-&gt;Send();
            echo 'OK';
          } catch (phpmailerException $e) {
            //echo $e-&gt;errorMessage();
            echo $mail-&gt;ErrorInfo; 
  
          } catch (Exception $e) {
            echo 'NO';//Boring error messages from anything else!
          }
      }
      ?&gt;
  </code></pre>
  
  <p>So my problem is the following: I get an "Invalid Address:"" Error. When I comment this line: </p>
  
  <pre><code>$mail-&gt;AddAddress($email,'test'); 
  </code></pre>
  
  <p>And uncomment this line: </p>
  
  <pre><code>$mail-&gt;AddAddress('******@****.agency','K L'); 
  </code></pre>
  
  <p>Passing a string value works. So the problem clearly is that the <code>$email</code> variable somehow isn't accepted. The var_dump outputs this: <code>"string(24) "*******@****.com"</code> so it is a string. </p>
  
  <p>I've searched in already existing answers and couldn't find that specific issue.</p>
  
  <p>Any help is greatly appreciated.</p>