title: How do you send email from IMAP account with PHP?
body: <p>I'm having an issue sending email via PHP/IMAP - and I don't know if it's because:</p>
  
  <ul>
  <li>I don't correctly understand IMAP, or</li>
  <li>there's an issue with my server</li>
  </ul>
  
  <p>My application opens an IMAP connection to an email account to read messages in the inbox. It does this successfully. The problem I have is that I want to send messages from this account and have them display in the outbox/sent folder.</p>
  
  <p>As far as I can tell, the PHP imap_mail() function doesn't in any way hook into the IMAP stream I currently have open.</p>
  
  <p>My code executes without throwing an error. However, the email never arrives to the recipient and never displays in my sent folder.</p>
  
  <pre><code>private function createHeaders() {
      return "MIME-Version: 1.0" . "\r\n" .
          "Content-type: text/html; charset=iso-8859-1" . "\r\n" .
          "From: " . $this-&gt;accountEmail . "\r\n";
  }
  
  private function notifyAdminForCompleteSet($urlToCompleteSet) {
      $message = "
          &lt;p&gt;
              In order to process the latest records, you must visit
              &lt;a href='$urlToCompleteSet'&gt;the website&lt;/a&gt; and manually export the set.
          &lt;/p&gt;
      ";
  
      try {
          imap_mail(
              $this-&gt;adminEmail,
              "Alert: Manual Export of Records Required",
              wordwrap($message, 70),
              $this-&gt;createHeaders()
          );
          echo("   ---&gt; Admin notified via email!\n");
      }
      catch (Exception $e) {
          throw new Exception("Error in notifyAdminForCompleteSet()");
      }
  }
  </code></pre>
  
  <p>I'm guessing I need to copy the message into the IMAP account manually... or is there a different solution to this problem?</p>
  
  <p>Also, does it matter if the domain in the "from" address is different than that of the server on whicn this script is running? I can't explain why the message is never sent.</p>