ActiveXperts Email Component

Quicklinks

ActiveXperts Email Component is a software development kit (SDK) that enables the user to send (SMTP) and receive (POP3) e-mail messages. ActiveXperts Email Component supports SMTP, POP3, multiple recipients (To, CC, BCC), multiple attachments (ASCII and binary), rich text body formats (RTF/HTML), Unicode, multiple character sets, SMTP authorization (AUTH PLAIN, AUTH LOGIN, AUTH CRAM MD5), POP3 authorization (Plain, APOP), POP3 header download, different character sets (including arabic, chinese, japanese, russian, greek, hebrew and many more), different encodings (including 7/8 bit, quoted-printable, base64).


Introduction

In this example we are going to create a PHP page to receive e-mail messages. This demo project will ask the user to give an e-mail address and a password on the command prompt to connect and download messages from a POP3 server.

Step 1: Installation of ActiveXperts Email Component

On each client PC, download ActiveXperts Email Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create the E-mail objects in PHP

You must use the following code to declare the COM object(s) in PHP:

Use the following PHP code to declare and create the 'objPop3' object:

$objPop3 = new COM ("AxEmail.Pop3");

Step 3: receive E-mail messages

You can now receive E-mail messages.

The following PHP code will download all messages from the POP3 server and save them in an array:

if ($objPop3->LastError == 0)
{
  for ($i = 1; $i <= $numMessages; $i++)
  {
    $objEmail = $objPop3->GetEmailHeader($i);
    
    if ($objPop3->LastError == 0)
      $arrMails[] = $objEmail;
  }
}

Appendix: Full source code

Following you can find the full source code which is also included in the ActiveXperts Email Component package.

<?php
  $arrMails = array();
  $strResult = 'n/a';
  
  $objPop3 = new COM ("AxEmail.Pop3");
  $objPop3->LogFile = sys_get_temp_dir()."AxEmail.Pop3.log"; 
  // Windows default: 'C:\Windows\Temp\AxEmail.Pop3.log'
  
  if (isset($_POST['btnListMessages']))
  {
    $objEmailConstants = new COM("AxEmail.Constants");
    $objEmail = new COM("AxEmail.Message");
    
    $objPop3->Authentication = $objEmailConstants->POP3_AUTH_AUTO;
    
    if (isset($_POST['cbxSecure']))
      $objPop3->SetSecure(995); // 995 is the default secure POP3 port
    
    if ($objPop3->LastError == 0)
    {
      $objPop3->Connect($_POST['txtHost'], $_POST['txtAccount'], $_POST['txtPassword']);
    }
    
    if ($objPop3->LastError == 0)
    {
      $numMessages = $objPop3->CountMessages();
    }
    
    if ($objPop3->LastError == 0)
    {
      for ($i = 1; $i <= $numMessages; $i++)
      {
        $objEmail = $objPop3->GetEmailHeader($i);
        
        
        if ($objPop3->LastError == 0)
          $arrMails[] = $objEmail;
      }
    }
    
    $strResult = $objPop3->LastError . ": " . $objPop3->GetErrorDescription($objPop3->LastError);
  }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>ActiveXperts ActiveXperts Email Component Demo</title>
  <link rel="Stylesheet" type="text/css" href="css/Layout.css" />
</head>
<body>
  <div class="ax_maincontainer">
    <div class="ax_header">
      <div class="ax_stroke"></div>
      <div class="ax_logo"></div>
    </div><!-- /header -->

    <div class="ax_container">
      <h1>ActiveXperts ActiveXperts Email Component PHP POP3 Sample</h1>
      <hr />
      <p>
        Simple Mail Transfer Protocol (SMTP) is an Internet standard for electronic mail (e-mail) 
        transmission across Internet Protocol (IP) networks.
        SMTP is specified for outgoing mail transport and uses TCP port 25 by default.
      </p>
      <form action="pop3.php" method="post">
        <h2>ActiveXperts Email Component:</h2>
        <h3>Build: <?php echo $objPop3->Build ?>; Module: <?php echo $objPop3->Module ?></h3>
      
        <!-- Host, Secure -->
        <label for="Host">Mailserver:</label>
        <p>
          <input type="text" id="Host" name="txtHost" value="pop3.mycompany.com" />
          
          <input type="checkbox" class="ax_cbFix" id="Secure" name="cbxSecure" value="1" />
          <label for="Secure">Secure</label>
        </p>
        
        <!-- Account -->
        <label for="Account">Account:</label>
        <p>
          <input type="text" id="Account" name="txtAccount" value="user@mycompany.com" />
        </p>
        
        <!-- Password -->
        <label for="Password">Password:</label>
        <p>
          <input type="password" id="Password" name="txtPassword" value="" />
        </p>
        
        <!-- Empty row -->
        <div class="ax_clearRow"></div>
        
        <!-- List Messages button -->
        <div class="ax_clearLabel"></div>
        <p>
          <input type="submit" name="btnListMessages" value="List Messages" />
        </p>
        
        <!-- Messages Listbox -->
        <label for="Received">Messages received:</label>
        <p>
          <select id="Received" class="ax_FullWidth" name="lvMessages" size="10">
          <?php
          foreach($arrMails as $Mail)
          {
            echo '
            <option>'.$Mail->Date . ": " . $Mail->FromAddress . 
              "; Subject " . $Mail->Subject.'</option>';
          }
          ?>
          </select>
        </p>
        
        <!-- Result -->
        <label for="Result" class="ax_Bold">Result:</label>
        <p>
          <input type="text" id="Result" name="txtResult" class="ax_FullWidth Bold" 
              value="<?php echo $strResult; ?>" />
        </p>
      </form>  
      <p>
        This demo uses the ActiveXperts ActiveXperts Email Component, an 
        <a href="http://www.activexperts.com" target="_blank">
          ActiveXperts Software</a> product.<br />
        <a href="index.php">Back to main page</a> 
      </p>
    </div><!-- /container -->
    <div class="ax_footer">
      <div class="ax_icon"></div>
      <p>
        © 2011 <a href="http://activexperts.com" target="_blank">
        Active<font color="#CCC000000">X</font>perts Software B.V.</a> All rights reserved.
        <small>
  <a href="http://activexperts.com/activexperts/contact" target="_blank">Contact Us</a> |
  <a href="http://activexperts.com/activexperts/termsofuse" target="_blank">Terms of Use</a> |
  <a href="http://activexperts.com/activexperts/privacypolicy" target="_blank">Privacy Policy</a>
        </small>
      </p>
    </div><!-- /footer -->
  </div><!-- /maincontainer -->
</body>
</html>

You can download the full source code of this project from the ActiveXperts FTP site: ftp://ftp.activexperts-labs.com/samples/smtp-pop3-component/. There are many other working samples included with the product or on the FTP site.

NOTE: Demo Projects are created with Microsoft Visual Studio 2008

The ActiveXperts Email Component project ships with a set of Microsoft Visual Studio .NET samples. The projects are created with Microsoft Visual Studio 2008.

Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.