Setting up a local Ubuntu Linux machine to send email via SMTP in PHP

The following guide worked on an Ubuntu 11.04 machine.

I will assume you have an Apache2 server up and running without problems. If this is not the case, search the Ubuntu forums for LAMP.

Begin with installing the packages sendmail, php-mail and postfix:

sudo apt-get install sendmail php-mail postfix

You might get some prompts during the installation, but just follow the instructions.

Uncomment and change the sendmail_path in your file /etc/php5/apache2/php.ini. The line should now look like this:

sendmail_path = /usr/sbin/sendmail -i -t

This is needed because PHP won’t find the sendmail command otherwise.

You can either use the PHP mail() function now, or use a custom PHP library for sending emails. I recommend the latter. For a fast setup, use the Swift Mailer. Download the library, put it in your public website folder and start making scripts. Here is an example script that uses Swift:

require_once 'swift/lib/swift_required.php';

// --- Create the Transport ---
$transport = Swift_SmtpTransport::newInstance('', 587)

// --- Create the Mailer using your created Transport ---
$mailer = Swift_Mailer::newInstance($transport);

// --- Create a message ---
$message = Swift_Message::newInstance($subject)
  ->setFrom(array('' => 'Your Name'))
  ->setBody('This is the message body.');

// --- Send message ---
$status = $mailer->send($message);
if($status) echo "Success!";
else echo "Failure";

Put this code into a PHP file, change the domain and SMTP server data, and run it. Hopefully, an email should be sent to the given e-mail address. is temporarily down!

Update: A temporary site has been setup at:

This site has been suspended.

I’m sorry to announce it, but this is the case. I’ll do what I can do bring it back up as soon as possible. I can’t control this downtime since the site sits on a remote web hotel.

I am very keen on switching to some other web hotel. For a “big” customer like me, this current one seem to have too many problems and is quite unsafe. They can’t offer a larger account for me either! Anyway – stay connected via Facebook!

This is the answer I got from my current web host when I asked for the reason why they suspended me.

Hello Stefan,
Your site was suspended because your site was causing too much load on
the database server. You must fix your script to reduce the database
load and minimize the database queries.
Best Regards

Of course, the database load is proportional to the number of visitors. Which is a very big number. I see no other solution than moving to some other web host. I guess that will be the project for this week and next.

Now I’ve bought some web space at, a Swedish web host with good performance of servers and good reputation. Going from to will be a HUGE performance increase. As a user, you’ll probably feel the difference right away. This web hotel know know what they are doing – they’ve worked with big customers for ages. I took the smaller account and I think that will fit me just fine 🙂

Now I’m uploading all the old things to the new server. This will take a lot of time but I’ll do it for my users. The site can be reached from a random URL in the beginning, but the domain “” will point to it when the guys at and the registrars have finished the work I gave them today.

bah! I’m having withdrawls!

I wanted to try making the bracelet buckle last night but the site shut down and I freaked out haha :p

‎:((( no no no no no… i cant wait…

im so nervous!! im like obsessed with this

WHY? ! I just started this braceletttttt. And now it is in hold. D;

I think being without is probably worse than being without facebook :p


Uploading thousands and thousands and thousands and *looks at watch* thousands and…. Yeah, I think you get it. I’ve already been sitting here for like three hours. The move to a new webhotel is painful but it will be a lot better when it’s done.

Update: A temporary site has been setup at: