PHPMailer .Exception:SendAsDeniedException.MapiExceptionSendAsDenied
<p>I have installed PHPMailer on my website. But, I can't get it to work the way it should. When I send an email through the website, I get the following error:</p>

<pre><code>08:12:53    CLIENT -&gt; SERVER: RCPT TO: 2016-10-13 08:12:53
CLIENT -&gt; SERVER: DATA 2016-10-13 08:12:53  
CLIENT -&gt; SERVER: Date: Thu, 13 Oct 2016 08:12:51 +0000 2016-10-13 08:12:53
CLIENT -&gt; SERVER: To: Kevin Kloet 2016-10-13 08:12:53   
CLIENT -&gt; SERVER: From: Name &lt;myEmail@email.com&gt; 2016-10-13 08:12:53
CLIENT -&gt; SERVER: Reply-To: Name &lt;myEmail@email.com&gt; 2016-10-13 08:12:53    
CLIENT -&gt; SERVER: Subject: Subject 2016-10-13 08:12:53  
CLIENT -&gt; SERVER: Message-ID: 2016-10-13 08:12:53   
CLIENT -&gt; SERVER: X-Mailer: PHPMailer5.2.15 (https://github.com/PHPMailer/PHPMailer) 2016-10-13 08:12:53    
CLIENT -&gt; SERVER: MIME-Version: 1.0 2016-10-13 08:12:53 
CLIENT -&gt; SERVER: Content-Type: text/plain; charset=UTF-8 2016-10-13 08:12:53   
CLIENT -&gt; SERVER: 2016-10-13 08:12:53   
CLIENT -&gt; SERVER: Name: Name 2016-10-13 08:12:53    
CLIENT -&gt; SERVER: Email: myEmail@email.com 2016-10-13 08:12:53  
CLIENT -&gt; SERVER: Subject: Subject 2016-10-13 08:12:53  
CLIENT -&gt; SERVER: Message: message 2016-10-13 08:12:53  
CLIENT -&gt; SERVER: 2016-10-13 08:12:53   
CLIENT -&gt; SERVER: . 2016-10-13 08:12:57 
SMTP ERROR: DATA END command failed: 550 5.3.4 554-554 5.2.0 
STOREDRV.Deliver; delivery result banner 2016-10-13 08:12:57    
--------&gt; SMTP Error: data not accepted. Message was not sent.Mailer error: &lt;--------
--------&gt; SMTP Error: data not accepted.SMTP server error: &lt;--------
DATA END command failed Detail: 554-554 5.2.0 
STOREDRV.Deliver; delivery result banner SMTP code: 550 Additional SMTP
info: 5.3.4echo2016-10-13 08:12:57  
CLIENT -&gt; SERVER: QUIT 2016-10-13 08:12:57  
SMTP ERROR: QUIT command failed: 554-554 5.2.0
STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied;
Failed to process message due to a permanent exception with message Cannot
submit message. 16.55847:6900000
</code></pre>

<p>I put arrows where the actual error is. When I try to send an email using the same email as the receiving email, everything works the way I want it to.
That's why I don't get it why it does this?</p>

<p>Here is the code that is used to send the email:</p>

<pre><code>require("PHPMailerAutoload.php");

$mail = new PHPMailer();
$mail-&gt;IsSMTP();
$mail-&gt;Mailer = "smtp";
$mail-&gt;CharSet = 'UTF-8';
$mail-&gt;Host = 'tls://smtp-mail.outlook.com';
$mail-&gt;Port = "587"; // 8025, 587 and 25 can also be used. Use Port 465 for SSL.
$mail-&gt;SMTPAuth = true;
$mail-&gt;SMTPSecure = 'tls';
$mail-&gt;Username = "username";
$mail-&gt;Password = "password";
$mail-&gt;From = trim_input($_POST['Email']);
$mail-&gt;FromName = trim_input($_POST['Name']);
$mail-&gt;AddAddress("receivingEmailAdress@outlook.com", "my name");
$mail-&gt;AddReplyTo(trim_input($_POST['Email']), trim_input($_POST['Name']));
$mail-&gt;SMTPDebug = 1;
$mail-&gt;Subject = trim_input($_POST['Subject']);
$mail-&gt;Body = trim_input($_POST['message']);
$mail-&gt;WordWrap = 50;

if (!$mail-&gt;Send()) {
    echo 'Message was not sent.';
    echo 'Mailer error: ' . $mail-&gt;ErrorInfo;
    exit;
} else {
    echo 'Message has been sent.';
}
</code></pre>

<p>The php_openssl extension is enabled.
I am using actual email addresses so it's not the case of using fake email addresses like example@example.com.</p>

<p>My html:</p>

<pre><code>&lt;!-- modal --&gt;
&lt;div id="myModal" class="modal fade" role="dialog"&gt;
  &lt;div class="modal-dialog"&gt;

    &lt;!-- Modal content--&gt;
    &lt;div class="modal-content"&gt;
      &lt;div class="modal-header"&gt;
        &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times&lt;/button&gt;
        &lt;h4 class="modal-title"&gt;Bericht sturen&lt;/h4&gt;
      &lt;/div&gt;
      &lt;form method="POST" action="" &gt;
      &lt;div class="modal-body"&gt;
          &lt;label for="messageName"&gt;Uw naam: &lt;/label&gt;
          &lt;input type="text" id="messageName" name="Name" /&gt;
          &lt;label for="messageEmailAdress"&gt;Uw Emailadres: &lt;/label&gt;
          &lt;input type="text" id="messageEmailAdress" name="Email" /&gt;
          &lt;label for="messageSubject"&gt;Onderwerp van uw bericht: &lt;/label&gt;
          &lt;input type="text" id="messageSubject" name="Subject" /&gt;
          &lt;label for="message"&gt;bericht:  &lt;/label&gt;
          &lt;textarea id="message" rows="4" cols="50" name="Message"&gt;&lt;/textarea&gt;
          &lt;input type="hidden" name="totalMessage" /&gt;
      &lt;/div&gt;
      &lt;div class="modal-footer"&gt;
        &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Sluiten&lt;/button&gt;
        &lt;input type="submit" name="Submit" class="btn btn-primary" value="Stuur bericht" /&gt;
      &lt;/div&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>and the javascript for the totalMessage:</p>

<pre><code>jQuery(document).ready(function () {
var form = document.getElementsByTagName('form')[0];
if (form) {
    form.addEventListener('submit', contact, false);
}
function contact(e) {
    // Prevent Default Form Submission
    e.preventDefault();

    var target = e.target || e.srcElement;
    var i = 0;
    var message = '';

    // Loop Through All Input Fields
    for (i = 0; i &lt; target.length; ++i) {
        // Check to make sure it's a value. Don't need to include Buttons
        if (target[i].type != 'text' &amp;&amp; target[i].type != 'textarea') {
            // Skip to next input since this one doesn't match our rules
            continue;
        }

        // Add Input Name and value followed by a line break
        message += target[i].name + ': ' + target[i].value + "\r\n";
    }

    target.elements["totalMessage"].value = message;
    this.submit();
    }
  }
);
</code></pre>

<p>What am I doing wrong here or what is the problem? Why I get the error message?</p>

<p>edit:</p>

<p>debug level 2 error:</p>

<pre><code>2016-10-13 10:13:42    SERVER -&gt; CLIENT: 220 BLU436-SMTP224.smtp.hotmail.com Microsoft ESMTP MAIL Service, Version: 8.0.9200.16384 ready at Thu, 13 Oct 2016 03:13:39 -0700
2016-10-13 10:13:42    CLIENT -&gt; SERVER: EHLO localhost
2016-10-13 10:13:42    SERVER -&gt; CLIENT: 250-BLU436-SMTP224.smtp.hotmail.com Hello [82.176.119.145] 250-TURN 250-SIZE 41943040 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING 250-VRFY 250-TLS 250-STARTTLS 250 OK
2016-10-13 10:13:42    CLIENT -&gt; SERVER: STARTTLS
2016-10-13 10:13:42    SERVER -&gt; CLIENT: 220 2.0.0 SMTP server ready
2016-10-13 10:13:42    CLIENT -&gt; SERVER: EHLO localhost
2016-10-13 10:13:42    SERVER -&gt; CLIENT: 250-BLU436-SMTP224.smtp.hotmail.com Hello [82.176.119.145] 250-TURN 250-SIZE 41943040 250-ETRN 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8bitmime 250-BINARYMIME 250-CHUNKING 250-VRFY 250-AUTH LOGIN PLAIN XOAUTH2 250 OK
2016-10-13 10:13:42    CLIENT -&gt; SERVER: AUTH LOGIN
2016-10-13 10:13:42    SERVER -&gt; CLIENT: 334 VXNlcm5hbWU6
2016-10-13 10:13:42    CLIENT -&gt; SERVER: xxx==
2016-10-13 10:13:42    SERVER -&gt; CLIENT: 334 UGFzc3dvcmQ6
2016-10-13 10:13:42    CLIENT -&gt; SERVER: xxx
2016-10-13 10:13:43    SERVER -&gt; CLIENT: 235 2.7.0 Authentication succeeded
2016-10-13 10:13:43    CLIENT -&gt; SERVER: MAIL FROM:
2016-10-13 10:13:43    SERVER -&gt; CLIENT: 250 2.1.0 mySendingEmailaddress@email.com....Sender OK
2016-10-13 10:13:43    CLIENT -&gt; SERVER: RCPT TO:
2016-10-13 10:13:43    SERVER -&gt; CLIENT: 250 2.1.5 myReceivingEmailaddress@email.com
2016-10-13 10:13:43    CLIENT -&gt; SERVER: DATA
2016-10-13 10:13:43    SERVER -&gt; CLIENT: 354 Start mail input; end with .
2016-10-13 10:13:43    CLIENT -&gt; SERVER: Date: Thu, 13 Oct 2016 10:13:41 +0000
2016-10-13 10:13:43    CLIENT -&gt; SERVER: To: Kevin Kloet
2016-10-13 10:13:43    CLIENT -&gt; SERVER: From: this is my name
2016-10-13 10:13:43    CLIENT -&gt; SERVER: Reply-To: this is my name
2016-10-13 10:13:43    CLIENT -&gt; SERVER: Subject: subject
2016-10-13 10:13:43    CLIENT -&gt; SERVER: Message-ID: &lt;3e21fa1900a9d30d3d51187e7719add6@localhost&gt;
2016-10-13 10:13:43    CLIENT -&gt; SERVER: X-Mailer: PHPMailer 5.2.16 (https://github.com/PHPMailer/PHPMailer)
2016-10-13 10:13:43    CLIENT -&gt; SERVER: MIME-Version: 1.0
2016-10-13 10:13:43    CLIENT -&gt; SERVER: Content-Type: text/plain; charset=UTF-8
2016-10-13 10:13:43    CLIENT -&gt; SERVER:
2016-10-13 10:13:43    CLIENT -&gt; SERVER: Name: this is my name
2016-10-13 10:13:43    CLIENT -&gt; SERVER: Email: mySendingEmail@email.com
2016-10-13 10:13:43    CLIENT -&gt; SERVER: Subject: subject
2016-10-13 10:13:43    CLIENT -&gt; SERVER: Message: this is the message
2016-10-13 10:13:43    CLIENT -&gt; SERVER:
2016-10-13 10:13:43    CLIENT -&gt; SERVER: .
2016-10-13 10:13:49    SERVER -&gt; CLIENT: 550 5.3.4 554-554 5.2.0 STOREDRV.Deliver; delivery result banner
2016-10-13 10:13:49    SMTP ERROR: DATA END command failed: 550 5.3.4 554-554 5.2.0 STOREDRV.Deliver; delivery result banner
2016-10-13 10:13:49    SMTP Error: data not accepted. Message was not sent.Mailer error: 
    SMTP Error: data not accepted.
    SMTP server error: DATA END command failed Detail: 554-554 5.2.0
    STOREDRV.Deliver; delivery result banner 
    SMTP code: 550 Additional 
    SMTP info: 5.3.4echo
2016-10-13 10:13:49    CLIENT -&gt; SERVER: QUIT
2016-10-13 10:13:49    SERVER -&gt; CLIENT: 554-554 5.2.0
    STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:6900000 2016-10-13 10:13:49  
    SMTP ERROR: QUIT command failed: 554-554 5.2.0
    STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:6900000
</code></pre>

<p>edit 2:</p>

<p>the trim_input function if you need to know what it does:</p>

<pre><code>function trim_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
</code></pre>