How To : Send email with PHP from localhost

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:

sudo apt-get install ssmtp

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

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

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

sendmail_path = /usr/sbin/sendmail -t

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

(Visited 110 times, 1 visits today)

1 Comment

  1. Musa January 3, 2016 at 7:16 PM

    Excellent Writing…We are excepting more form you 🙂

Leave a comment

Your email address will not be published. Required fields are marked *