Tapan's World

Tapan Kumer Das

Darus Sallam, Mirpur, Dhaka, Bangladesh
Tapan Kumer Das

How To : Send email with PHP from localhost

January 3, 2016, by tapan, category How To, LAMP, Linux, PHP, Ubuntu

Hello!

Happy New Year! Hope you all are doing well.

Last couple of months I have been thinking about mail sending option of PHP application from local development server. Generally I uploaded my script to online web server for send mail from PHP. Today I think that I need to configure my local server so that I can send emails from localhost. I searched a lot and found there is multiple options like configure postfix, sendmail, msmtp, ssmtp etc. Where I found that ssmtp is a easy way to install/configure for send email from PHP in a LAMP server.

Here is how you can install and configure ssmtp in Ubuntu (I am using Ubuntu 14.04 but it seems to be same on other version too).

Install ssmtp by running:

Then edit /etc/ssmtp/ssmtp.conf file, comment out existing mailhub line and add the following lines (this example is for gmail smtp server):

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

Now make sure that your php.ini has correct sendmail_path. It should read as:

Reload apache and bingo! Your PHP application should be able to send outgoing emails from now on.

One Comment

So, what do you think ?