Use PHP Mail for Windows
In the perpetual search for useful, utilitarian user utilities and other things beginning with 'U', Brad 'BradMail' Robinson sets up some email forms on his company's intranet using PHP (which begins with 'P'..)
PHP
Yes indeedy. PHP stands for
PHP: Hypertext Preprocessor which is a
recursive acronym, much loved by open source geeky types for some reason. PHP is an HTML-embedded scripting language, which is quite a mouthfull as well as a 'server-side' technology. Much of its syntax is borrowed from C, Java and Perl, with a couple of unique PHP-specific features thrown in for good measure. The version used here is 4.3.7 but grab the latest version from
SourceForge.net.
Email Forms
The very same. Y'know when you click on a web page and a form comes up with fields which can be completed and a 'send' button at the bottom.. well that's server side scripting in action. It may be using PHP or its close relative, PERL. Emails can be sent from an HTML-based form in the same way.
Under PERL, the most popular technology is called
sendmail, while under PHP the version we are using is called
phpmailer. Both of these technologies are steeped in Unix tradition, but versions are also available for Win32. In this example we will be using the Windows version running under Apache. The necessary files have been minimised in quantity to get things up and running quickly:
Download PHPMailer v1.72 [cut down version]. I can't remember if these are meant for Unix or Win32, but they are working on my Win2000 Server and also on my Linux-hosted web site, so there you go. A script for all seasons. Splendid, splendid..
Pre-requisites for this activity include Apache running on Win32 with PHP installed. See
Squirrelmail webmail on Windows for how to get Apache and PHP up and running on Windows 2000 Server.
With PHP happening, I unzip the
phpmailer.zip files into a subdirectory of Apache called
\Mail. The four required files are
class.phpmailer.php,
class.smtp.php,
email.php and the
email.htm file which is the email form itself:
class.phpmailer.php
This file requires no additional configuration, although its variables are listed
here.
class.smtp.php
This file requires no additional configuration.
email.htm
This is the html file which describes the web page containing the form fields. Take a look at it in a text editor. Tart it up as required. Note that it calls the
email.php file..
email.php
The last of the big four. This file must be edited in a text editor:
- $mail->Host = "localhost"; - change localhost to the name of the SMTP Server if required, although the default localhost means this machine
.
- $mail->AddAddress("andy@domain.net","Andy Mallett"); - change this line to the email address and username which mails will be sent to.
And that's all the configuration. Enter a URL to the directory containing the
email.htm and fill in the form. Note that the script searches for proper domain addresses and will error out if senders just put their name or a non-existent email host. For more information, go to PHPMailer at the link below.
Links
PHPMailer at SourceForge.net
PHP.net