Hello fsdolphin,
From the mail manual of php:
Requirements
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
cgi.fix_pathinfo=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 = 127.0.0.1:9000, and change the 127.0.0.1:9000 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 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;
}
}
SSMTP
Comment out or delete the existing config and use the following lines:
sudo nano /etc/ssmtp/ssmtp.conf
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
AuthUser=<YOUR-EMAIL>@gmail.com
AuthPass=<YOUR-PASSWORD>
(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 :)