title: PHPMailer Exchange Auth
body: <p>Im trying to send an E-Mail via PHPMailer. For some Reason I dont understand the authentification fails. </p>
  
  <p>I also tried different things like setting authentification to PLAIN and The Secure Method to TLS, but it doesnt seem to help.</p>
  
  <p>Our Exchange has a Sending Connector, which is sending the E-Mails to our Spam Proxy, which is sending the Mails out to a Mail Server, which is encrypting the Mails with DKIM.</p>
  
  <p>This is my Code:</p>
  
  <pre><code>$mail = new PHPMailer();
  
          $mail-&gt;IsSMTP();                                      // set mailer to use SMTP
          $mail-&gt;Host = $settings['mailserver'];  // specify main and backup server
          $mail-&gt;SMTPAuth = true;     // turn on SMTP authentication
          $mail-&gt;Port = "25";
          $mail-&gt;Username = $settings['mail_domain']."\\".$settings['mail_username'];  // SMTP username
                      echo $mail-&gt;Username;
          $mail-&gt;Password = $settings['mail_password']; // SMTP password
          $mail-&gt;SMTPOptions = array(
              'ssl' =&gt; array(
              'verify_peer' =&gt; false,
              'verify_peer_name' =&gt; false,
              'allow_self_signed' =&gt; true
              )
          );
  
                      $mail-&gt;SMTPDebug = 2;
  
          $mail-&gt;From = $settings['mail_sender'];
          $mail-&gt;AddAddress($emp_mail);           // name is optional
          $mail-&gt;AddReplyTo($settings['mail_sender']);
  
          $mail-&gt;WordWrap = 50;                                 // set word wrap to 50 characters
          //$mail-&gt;AddAttachment("/var/tmp/file.tar.gz");         // add attachments
          $mail-&gt;IsHTML(true);                                  // set email format to HTML
  
          $mail-&gt;Subject = "Neue Datei erhalten: ".$filename." - ".$_COOKIE['settings']['firmenname'];
          $mail-&gt;Body    = $text;
          $mail-&gt;AltBody = "Bitte laden Sie diese Email in der HTML Ansicht";
  
          if(!$mail-&gt;Send())
          {
              $return_code['Code'] = 500;
              $return_code['Msg'] = $mail-&gt;ErrorInfo.print_r($settings);
          }else{
              $return_code['Code'] = "200";
          }
  </code></pre>
  
  <p>And this is my answer:</p>
  
  <pre><code>2016-09-26 13:39:44 SERVER -&gt; CLIENT: 220-cpanel-1.fr-hostings.at ESMTP Exim 4.87 #1 Mon, 26 Sep 2016 15:39:44 +0200 
                                        220-We do not authorize the use of this system to transport unsolicited, 
                                        220 and/or bulk e-mail.
  2016-09-26 13:39:44 CLIENT -&gt; SERVER: EHLO transfer.feurich.com
  2016-09-26 13:39:44 SERVER -&gt; CLIENT: 250-cpanel-1.fr-hostings.at Hello cpanel-1.fr-hostings.at [92.222.157.38]
                                        250-SIZE 52428800
                                        250-8BITMIME
                                        250-PIPELINING
                                        250-AUTH PLAIN LOGIN
                                        250-STARTTLS
                                        250 HELP
  2016-09-26 13:39:44 CLIENT -&gt; SERVER: STARTTLS
  2016-09-26 13:39:44 SERVER -&gt; CLIENT: 220 TLS go ahead
  2016-09-26 13:39:44 CLIENT -&gt; SERVER: EHLO transfer.feurich.com
  2016-09-26 13:39:44 SERVER -&gt; CLIENT: 250-cpanel-1.fr-hostings.at Hello cpanel-1.fr-hostings.at [92.222.157.38]
                                        250-SIZE 52428800
                                        250-8BITMIME
                                        250-PIPELINING
                                        250-AUTH PLAIN LOGIN
                                        250 HELP
  2016-09-26 13:39:44 CLIENT -&gt; SERVER: AUTH LOGIN
  2016-09-26 13:39:44 SERVER -&gt; CLIENT: 334 VXNlcm5hbWU6
  2016-09-26 13:39:44 CLIENT -&gt; SERVER: xxx=
  2016-09-26 13:39:46 SERVER -&gt; CLIENT: 535 Incorrect authentication data
  2016-09-26 13:39:46 SMTP ERROR: Username command failed: 535 Incorrect authentication data
  2016-09-26 13:39:46 SMTP Error: Could not authenticate.
  2016-09-26 13:39:46 CLIENT -&gt; SERVER: QUIT
  2016-09-26 13:39:46 SERVER -&gt; CLIENT: 221 cpanel-1.fr-hostings.at closing connection
  2016-09-26 13:39:46 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
  </code></pre>
  
  <p>Any Ideas?</p>