Sending Email with CodeIgniter and Debian Wheezy through external SMTP (Ziggo)

It was quite a struggle to get the sending of email working on an intranet server of a customer. This server is a (virtual) Linux Debian Wheezy server with Gnome 2 desktop (I don’t like the command line very much). After searching the internet I found a lot about the Sendmail, Exim4 and the ssmtp Debian packages. At the end (after reading a lot of forums and blog articles) I concluded that getting your mail to work can be a hard bone to break. But then I found that great article from Valérian Saliou. This article is a lot like his but then as a walk through with almost genuine data. I got it working on at least 2 systems in different networks following the steps below.

Tip: make sure that your firewall is not blocking your intranet server for sending mail traffic to the internet!

Requirements for sending email with Debian and ssmtp

Setup for smtp over Debian


The data values below is fictitious but easy to translate to your own situation.

Local (intranet) server:

  • Linux : Debian Wheezy (can be running in an VMWare ESX environment)
  • DNS host name : intranet.local (this is the DNS name entry in your DNS server that you can ping all over your local network)
  • Package required : ssmtp (you can install this easy over the Synaptics Package Manager)


from the command line in a root terminal.

External smtp server:

We assume here a variation of a very well known provider in the Netherlands Ziggo.

  • smtp server :
  • port : 587 (default for most providers is port 25)
  • protocol : TLS (Ziggo doesn’t send unsecure)
  • user : (use your own user here)
  • password : pazzw@rd (use your own here)

Configuring the ssmtp package on the Debian server

Now open your favorite editor (I use mousepad or gedit) on the Debian server and open the file: etc/ssmtp/ssmtp.conf. In the file below you can see how the settings from above fit in.

Although the aim is to send emails the root parameters contains the email address that receives the email. Here you can put an email address that you have created for the intranet web master. This has to be a valid email address that can be verified by your external SMTP provider.

As you can see the port 587 is added to the mailhub host definition.

If your smtp server doesn’t require security (like unsecured and port 25) you have to set UseSTARTSSL and UseTLS to ‘no’. Then you don’t have to add 25 either at the mailhub parameter.

The FromLineOverride parameter allows users to modify the from email address. Usually your intranet (or web-) application uses the same email from address (like


Now open with your favorite editor the file: etc/ssmtp/revaliases and see below how the settings fit in.

Configuring php.ini

Open the file: etc/php5/apache/php.ini and search for the string: ‘[mail function]’. Change this to:

After you have modified and saved, you have to restart the Apache server to make these changes active. You can do this from a terminal by typing:

Configuring CodeIgniter

For our example we are using version 1.72 of the CodeIgniter PHP framework. Open the file email.php in the config folder of your application and see below how the settings fit in.

The commented lines have been left in deliberately.

CodeIgniter test controller

Create a controller file Mailtest.php in the main folder of your (test) application.

Well that speaks for itself. You can remove the comments before the ‘cc’ and ‘bcc’ and test this too, but that is outside the scope of this article.

You can test the script by simply putting //<yourdomain>/Mailtest or //<yourdomain>/index.php/Mailtest in the URL locator of your browser.

The output should look like this:

Sending mail with Debian, CodeIgniter and ssmtp


Thanks to Valérian Saliou for this great article on Waaave.

Johan van de Merwe
Dedicated to professional software development since 1985. Has worked since 1992 as IT manager in several international operating companies. Since 2007 CEO and Sencha Ext JS web application developer at Enovision GmbH.

Leave a Reply