Local Mail Server With HMailServer

When we write code to push out emails to our customers or visitors, we want to be confident it’s going to arrive at the destination, looking the way we expect.

Most local windows server setups with XAMPP or WAMP won’t by default be setup with a mail server and setting one up can be a pain.

Luckily hMailServer is an option that you may want to try out


This quick step-by-step guide should get you up and running with local mail functionality and a test script in under 20 minutes.

Start by going to www.hmailserver.com, click download in the menu and choose the latest build (hMailServer 5.6.4 – Build 2283).

Browse to the download location and open the exe file.

Follow Next as shown:



For testing the Mail You can follow the following tutorial

PHPMAILER: Attach A File To An Email In PHP

The steps below shows you how to set up and use the PHPMailer library:

  • Import the PHPMailer Lib into your project either using Autoloader or Include. Library can be found @
  • Implement the code as below:


$email = new PHPMailer();
$email->From = ‘##Source Mail ID##’;
$email->FromName = ‘##Mailer Name##’;
$email->Subject = ‘##Subject##’;
$email->Body = ‘##Content##’;
$email->AddAddress( ‘##destination Mail ID##’ );
$file = ‘##Path to File to be attached##’;
$email->AddAttachment( $file, ‘##label of file that is attached##’ );
return $email->Send();

if we want to attach a file to an email directly from an upload, you can pass in the uploaded file from the $_FILES global like so
$email->AddAttachment( $_FILES['attachment']['tmp_name'], $_FILES['attachment']['name'] );

Make sure your mail server is configured and is working. In case not then follow this to setup a local open source mail server