Home >How to Send Email from localhost

How to Send Email from localhost

On localhost using windows

First of all, Xampp setup is needed. In Xampp window, you can check Config button →  choose PHP as demonstrated below:

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

And don’ forget to leave this comment

;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

(Here remember to add “;” at the beginning)

Suppose Xampp default installation is located at C:\Xampp, you only need to open file C:\xampp\sendmail\sendmail.ini and also fix some given lines:

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com

Finally, let’s restart Xampp services by clicking Stop →  Start. That’s not so complicating , is it? Now try to run php script and send email to see the results.

On localhost using ubuntu

Suppose localhost has been already installed Apache2, Mysql and PHP5

  • Install SSMTP: Go to terminal and type sudo apt-get install ssmtp. Then choose Y(yes) and click enter if confirmation is needed.
  • SSTMP configuration: Still in terminal, please continue to sudo gedit /etc/ssmtp/ssmtp.conf. When gedit window opens, you must add and fix following lines:
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
AuthUser=<YOUR-EMAIL>@gmail.com
AuthPass=<YOUR-PASSWORD>

In which <YOUR-EMAIL> and <YOUR-PASSWORD> are the information to sign in your email. Mailhub might be another stmp server in case you do not use Gmail. For the next step, just need to save and close gedit window to return to terminal.

  • Reset configuration sendmail_path for php: In terminal, you continue to type sudo gedit /etc/php5/apache2/php.ini. When gedit opens, it is the time to look up for the keyword sendmail_path then edit as sendmail_path = /usr/bin/msmtp -t
  • Save and close php.ini file. Again, from terminal you type this line to restart apache2: sudo service apache2 restart

So, when you get here, the configuration is completed. Now run php script to send email and you will be satisfied with the results.

< Previous Post
Next Post >
+ posts