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 send E-mail messages. This demo project will ask the user to give an e-mail address and a message body on the command prompt.
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. We will use the 'objSmtp' object to send the message itself. The 'objEmail' object will be used to store information of the message and the 'objEmailConstants' object containes constant values releated to the e-mail objects.
Use the following PHP code to declare and create the objSmtp object:
$objSmtp = new COM ("ActiveEmail.Smtp");
$objEmail = new COM ("ActiveEmail.EmailMessage");
$objEmailConstants = new COM ("ActiveEmail.EmailConstants");
The following code will ask the user for the recipient e-mail address and the content of the text message. You can also specify a CC or BCC recipient and you can also add an attachment to your message. This data will be stored in the 'objEmail' object.
$objEmail->FromName = $_POST['txtFromName'];
$objEmail->FromAddress = $_POST['txtFromAddress'];
if ($_POST['txtToAddress'] != "")
{
$objEmail->AddTo ($_POST['txtToAddress'], $_POST['txtToAddress']);
}
if ($_POST['txtCcAddress'] != "" && $objEmail->LastError == 0)
{
$objEmail->AddCc ($_POST['txtCcAddress'], $_POST['txtCcAddress']);
}
if ($objEmail->LastError == 0 && $_POST['txtBccAddress'] != "")
{
$objEmail->AddBcc($_POST['txtBccAddress'], $_POST['txtBccAddress']);
}
if ($objEmail->LastError == 0)
{
$objEmail->Subject = $_POST['txtSubject'];
$objEmail->Encoding = $_POST['ddlEncoding'];
$objEmail->Priority = $_POST['ddlPriority'];
$objEmail->BodyPlainText = $_POST['txtPlainBody'];
$objEmail->BodyHtml = $_POST['txtHtmlBody'];
if (isset($_POST['cbxSecure']))
$objSmtp->SetSecure(465); // 465 is the generic secure SMTP port
}
The following code shows how to send an e-mail message using the data that was stored in the 'objEmail' object.
if ($objEmail->LastError == 0 && $objSmtp->LastError == 0)
{
$objSmtp->Send($objEmail);
}
Following you can find the full source code which is also included in the ActiveEmail Toolkit package.
<?php
$strResult = 'n/a';
$objSmtp = new COM ("ActiveEmail.Smtp");
$objSmtp->LogFile = sys_get_temp_dir()."ActiveXperts.Smtp.log";
// Windows default: 'C:\Windows\Temp\ActiveXperts.Smtp.log'
if (isset($_POST['btnSendMessage']))
{
$objEmail = new COM ("ActiveEmail.EmailMessage");
$objEmailConstants = new COM ("ActiveEmail.EmailConstants");
$objEmail->FromName = $_POST['txtFromName'];
$objEmail->FromAddress = $_POST['txtFromAddress'];
if ($_POST['txtToAddress'] != "")
{
$objEmail->AddTo ($_POST['txtToAddress'], $_POST['txtToAddress']);
}
if ($_POST['txtCcAddress'] != "" && $objEmail->LastError == 0)
{
$objEmail->AddCc ($_POST['txtCcAddress'], $_POST['txtCcAddress']);
}
if ($objEmail->LastError == 0 && $_POST['txtBccAddress'] != "")
{
$objEmail->AddBcc($_POST['txtBccAddress'], $_POST['txtBccAddress']);
}
if ($objEmail->LastError == 0)
{
$objEmail->Subject = $_POST['txtSubject'];
$objEmail->Encoding = $_POST['ddlEncoding'];
$objEmail->Priority = $_POST['ddlPriority'];
$objEmail->BodyPlainText = $_POST['txtPlainBody'];
$objEmail->BodyHtml = $_POST['txtHtmlBody'];
if (isset($_POST['cbxSecure']))
$objSmtp->SetSecure(465); // 465 is the generic secure SMTP port
}
if ($objEmail->LastError == 0 && $objSmtp->LastError == 0)
{
$objSmtp->Connect($_POST['txtHost'], $_POST['txtAccount'], $_POST['txtPassword']);
}
if ($objEmail->LastError == 0 && $objSmtp->LastError == 0)
{
$objSmtp->Send($objEmail);
}
if ($objEmail->LastError != 0)
{
$strResult = $objEmail->LastError . ": " .
$objEmail->GetErrorDescription($objEmail->LastError);
}
else
{
$strResult = $objSmtp->LastError . ": " .
$objSmtp->GetErrorDescription($objSmtp->LastError);
}
$objSmtp->Disconnect();
}
?>
<!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 SMTP 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="smtp.php" method="post">
<h2>ActiveEmail Toolkit:</h2>
<h3>Build: <?php echo $objSmtp->Build ?>; Module: <?php echo $objSmtp->Module ?></h3>
<!-- Server, Secure -->
<label for="Server">Mailserver:</label>
<p>
<input type="text" id="Server" name="txtHost" value="smtp.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" />
*Only use when server requires authentication
</p>
<!-- Password -->
<label for="Password">Password*:</label>
<p>
<input type="password" id="Password" name="txtPassword" />
</p>
<!-- Empty row -->
<div class="clearRow"></div>
<!-- Sender Name -->
<label for="Sender">Sender name:</label>
<p>
<input type="text" id="Sender" name="txtFromName" />
</p>
<!-- Sender Email -->
<label for="Sender">Sender e-mail:</label>
<p>
<input type="text" id="Sender" name="txtFromAddress" />
</p>
<!-- Empty row -->
<div class="clearRow"></div>
<!-- To -->
<label for="To">To:</label>
<p>
<input type="text" id="To" name="txtToAddress" value="[ToAddress]" />
Note: Use ';' to split multiple email adresses
</p>
<!-- Cc -->
<label for="Cc">Cc:</label>
<p>
<input type="text" id="Cc" name="txtCcAddress" />
</p>
<!-- Bcc -->
<label for="Bcc">Bcc:</label>
<p>
<input type="text" id="Bcc" name="txtBccAddress" />
</p>
<!-- Empty row -->
<div class="clearRow"></div>
<!-- Subject -->
<label for="Subject">Subject:</label>
<p>
<input type="text" id="Subject" name="txtSubject" />
</p>
<!-- PlainBody -->
<label for="PlainBody">Body:</label>
<p>
<textarea id="PlainBody" name="txtPlainBody" style="height: 60px;"></textarea>
</p>
<!-- HtmlBody -->
<label for="HtmlBody">Body HTML (optional):</label>
<p>
<textarea id="HtmlBody" name="txtHtmlBody" style="height: 60px;"></textarea>
</p>
<!-- Empty row -->
<div class="clearRow"></div>
<!-- Char. Set -->
<label for="CharSet">Char. Set:</label>
<p>
<select name="ddlEncoding">
<option value="0">Standard</option>
<option value="65001">UTF8</option>
</select>
</p>
<!-- Priority -->
<label for="Priority">Priority:</label>
<p>
<select name="ddlPriority">
<option value="1">Highest Priority</option>
<option value="2">High Priority</option>
<option value="3" selected="true">Normal Priority</option>
<option value="4">Low Priority</option>
<option value="5">Lowest Priority</option>
</select>
</p>
<!-- SendButton -->
<div class="clearLabel"></div>
<p>
<input type="submit" name="btnSendMessage" value="Send Message" />
</p>
<!-- Empty row -->
<div class="clearRow"></div>
<!-- Result -->
<label for="Result"class="Bold">Result:</label>
<p>
<input type="text" id="Result" class="FullWidth Bold" name="txtResult"
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.