Is there some software that I need to install to be able to use a PHP contact form - It was working on a Share Hosting

August 29, 2015 1.7k views
Nginx Email PHP


I recently moved from a share hosting company to DO, I configured my server and everything is working fine except for a contact form that I have been using for years, I have php installed and it works with other PHP pages.

What I have is an HTML page (form) which sends a post request to a .php page. When I click the send button from the HTML form the server seems to process the PHP page because I see the HTML page that I created to notify the sender that the form was sent, but no email is really been sent.

Is there any software that I need to install in order to be able to send information through a form?

BTW I'm using Ubuntu and NGinx.


10 Answers

You have to install send mail. Taken from the comments on this post

I decided to install the sendmail-bin. I believe this is all that is needed. For sending mail from form etc.

2) $ sudo apt-get install sendmail-bin

Then checked hosts file.
3) $ nano /etc/hosts
Looked like: myhostname myhostname localhost
4) control+x to quit nano

Then ran:
5) $ sudo sendmailconfig

Accepted Y to all choices. I think there was three or four..Once finished..

Tested again with:
6) $ sendmail myemail@yahoo.com
Test message


Hmm, for some reason It doesn't work for me.

This is what I did...

  1. Install sendmail-ben
    sudo apt-get install sendmail-bin

  2. I looked at the hosts file but I didn't make any changes because it already had that right information.
    This is how it looks. MyDropletName MyDropletName localhost

  3. Ran
    sudo sendmailconfig

  4. Tested in terminal and using form and it just.
    In terminal
    a) sendmail someEmail@yahoo.com
    b) enter
    c) typed some text
    d) enter
    and nothing happen, no email was sent.

When I test it using the form I get the following error.
504 Gateway Time-out

Am I missing something? Any idea?

  • You need the sendmail for php. You can set up a mail server but that is a headache within itself.

    Try :

    apt-get install sendmail

Help me understand this better... do I need a mail server even to send an email from a contact form?

Installing sendmail didn't make a difference.
apt-get install sendmail

As I mentioned above I left the host file as it was it had the droplet name as the hostname, is the droplet name the hostname, is that right? Is your hostname usually the droplet name?

Host file: MyDropletName MyDropletName localhost


Hello fsdolphin,

From the mail manual of php:

For the mail functions to be available, PHP requires an installed and working email system. The program to be used is defined by the configuration settings in the php.ini file.

This means you have to install some sort of mailserver and configure php to use it.
If you would like to just send email from the contact form you got and nothing more, I recommend to keep it clean and fast. I do not know if you already got alot of services on your droplet, but I recommend to recreate it and follow my "tutorial". Things you need to do to get this working:

  • On a fresh droplet, install php-fpm and nginx.
  • Install the very simple and lightweight package ssmtp
  • Configure php,nginx,ssmtp

Inside your clean droplet, update it:

sudo apt-get update

Install nginx:

sudo apt-get install nginx

Install php-fpm:

sudo apt-get install php5-fpm

This will be enough to get your script working, however if you need more packages, install one or more of these. It depends what you want to run and whats needed for it:

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Install ssmtp:

sudo apt-get install ssmtp

Now configure your services
Change a security risk inside the php.ini:

 sudo nano /etc/php5/fpm/php.ini

Find the line, cgi.fix_pathinfo=1, and change the 1 to 0


Save and exit

Let php-fpm run on its socket. Edit www.conf:

 sudo nano /etc/php5/fpm/pool.d/www.conf

Find the line, listen =, and change the to /var/run/php5-fpm.sock.

listen = /var/run/php5-fpm.sock

Save and exit.
Now make sure that your php.ini has the correct sendmail_path:

sudo nano /etc/php5/fpm/php.ini

It should be like:

sendmail_path = /usr/sbin/sendmail -t

Open up the default virtual host file.

sudo nano /etc/nginx/sites-available/default

And use this default config, you can edit,add,remove whats needed:

server {
        listen   80;

        root /var/www;
        index index.php index.html index.htm;

        server_name IP or domain.com;

        location / {
                try_files $uri $uri/ /index.html;

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;

        # pass the PHP scripts to FastCGI server listening on the php-fpm socket
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;



Comment out or delete the existing config and use the following lines:

sudo nano /etc/ssmtp/ssmtp.conf 

(Provide your gmail username & password. Of course you can use any other SMTP server).

After installing and configurating everything, restart your services:

sudo service nginx restart
sudo service php5-fpm restart

Hope this small tutorial will help you and get it working. Please give report how it went, and if you like it a like :)

First of all thank you for your help.

Wow, it looks like a tedious process just to process a simple contact form. Why would I need to provide an email and password? I already have this defined in my PHP form. When I had this working in my previous share hosting I didn't have to do that, I guess that is the difference between mange your server your self vs share hosting.

All I want is to be able to send the information from the form as an email.


  • @fsdolphin

    It really isn't that hard :) It just looks like alot, but i've also explaint alot of it. If you just run the commands and edit some configs your done within 15 mins. You will just have to provide an email and password to get access to the GMAIL STMP servers. You don't have to use your own personal account, but could also use a new one. With the GMAIL SMTP servers you're always sure your email will get delivered.

    Well, the shared hosting servers already have a working email server wich your PHP script could use. When you are going to host your website, DB etc. on your own unmanaged server you need to configurate it all yourself. If you don't want to use this tutorial, so not using the gmail smtp server, you could use PHPMailer. This is also being used with alot of CMS systems, its possible to use without a SMTP server.

I just wanted to say thank you for following alone and for your time. I got it to work thanks to the following thread.


This is what I did that worked:

  1. Install sendmail-ben
    sudo apt-get install sendmail-bin

  2. Modified the hosts file to look as follow... localhost.localdomain localhost myDropletName

  3. Ran
    sudo sendmailconfig

  4. Restarted sendmail.
    sudo service sendmail restart

  5. Done.

To test it in the terminal do the following...

  1. type sudo sendmail youremail@hotmail.com
  2. hit enter
  3. Type a message
  4. Hit enter
  5. Type a "." and hit enter
  6. Done. Thanks a lot!
  • Good you got it working now. Sendmail is also a mailservice you could use, but less lightweight then ssmtp. When you got any more problems you could get back here.

One last question, do you know if there is any security configuration that I need to make for sendmail or there is nothing to worry about?

The reason for my question is because I have heard that mail servers need some sort of security configuration.


  • I haven't used sendmail in any professional way, so I haven't got any professional solution for that.
    But you can find plenty of explenations how to secure sendmail online.

Ok, I will try to find more information.
But in theory what are typically the security issues with mail-servers/services?

  • Most common issue is an open relay wich people could use to send spam. Bots are searching for these open relay servers all the time and once found it will be used to send spam.
    Also make firewall rules, DKIM, SPF if you want to make the setup better. But just looking into the information would be good as well to advance your knowledge.

Ok, thanks a lot for all of your help!

Have another answer? Share your knowledge.