Quicklinks
ActiveEmail SMTP/POP3 Toolkit is a software development kit (SDK) that enables the user to send (SMTP) and receive (POP3) e-mail messages. ActiveEmail 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).
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.
On each client PC, download the ActiveEmail Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
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 ("ActiveEmail.Pop3");
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;
}
}
Following you can find the full source code which is also included in the ActiveEmail Toolkit package.
<?php
$arrMails = array();
$strResult = 'n/a';
$objPop3 = new COM ("ActiveEmail.Pop3");
$objPop3->LogFile = sys_get_temp_dir()."ActiveXperts.Pop3.log";
// Windows default: 'C:\Windows\Temp\ActiveXperts.Pop3.log'
if (isset($_POST['btnListMessages']))
{
$objEmailConstants = new COM("ActiveEmail.EmailConstants");
$objEmail = new COM("ActiveEmail.EmailMessage");
$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 ActiveEmail Toolkit Demo</title>
<link rel="Stylesheet" type="text/css" href="css/Layout.css" />
</head>
<body>
<div class="maincontainer">
<div class="header">
<div class="stroke"></div>
<div class="logo"></div>
</div><!-- /header -->
<div class="container">
<h1>ActiveXperts ActiveEmail Toolkit 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>ActiveEmail Toolkit:</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="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="clearRow"></div>
<!-- List Messages button -->
<div class="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="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="Bold">Result:</label>
<p>
<input type="text" id="Result" name="txtResult" class="FullWidth Bold"
value="<?php echo $strResult; ?>" />
</p>
</form>
<p>
This demo uses the ActiveXperts ActiveEmail Toolkit, 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="footer">
<div class="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.
The ActiveEmail Toolkit 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.