Sending mail is a common task for many applications today. Whether sending mail
through a webform or as an automated tasks, sending mail can be simple using PHP
and PEAR. Using the sendMail() function below, you can send HTML formatted mail
through any smtp server.
Update March 11, 2009: Removed the demo since GoDaddy does not support
external SMTP servers.Update July 06, 2009: Updated variables for the usage example to be less
confusing. Thanks to David for pointing this out.
This function requires the following PEAR classes along
any of their dependencies.
This function assumes that you have your pear include path set correctly. You
can download the function here (right
click -> Save Link As) or copy the code from below. Scroll down for some
Using this function is simple. Simply pass in the parameters as described below:
$subject (required): Subject for the email message.
$smtp_server (required): SMTP Server host (ie. smtp.hostname.com).
$smtp_username (required): SMTP username.
$smtp_password (required): SMTP password.
$html (required): HTML version of the message body.
$text (required): Text version of the message body.
$to (required): String or array of email address to send the message to
(string may be comma separated list).
$from (required): Email address that the email is being sent from.
I have recently been working on a project to integrate with a
HarrisData ERP Application. The Application runs on
an IBM iSeries (AS/400). I used PHP’s built in PDO object with the ODBC
extension. Using PDO, I was able to execute SQL Queries on the server. IBM
systems use IBM’s DB2 syntax. This entry will outline some of the basic steps,
in PHP, to communicate with the system
Lately, I have been constantly switching between both operating systems and mail
clients. I became quite fond of Kontact, KDE’s PIM
suite, long ago. The only thing that stopped me from switching over to it full
time was its lack of support for HTML signatures. As of the KDE 4 release of
Kontact, support has been added for HTML signatures. I decided to make the
switch back to Kontact earlier this week.