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


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.



Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Ok, thanks a lot for all of your help!

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

@CrypticDesigns 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.


@CrypticDesigns 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
  2. hit enter
  3. Type a message
  4. Hit enter
  5. Type a “.” and hit enter
  6. Done. Thanks a lot!

@CrypticDesigns 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.


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 PHP 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

Nginx 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;

        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;


SSMTP 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).

Restarting 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 :)

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

Question: 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


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


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 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 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
Test message