How to enable PHP mail function on Ubuntu

Here are steps to follow:

First of all install packagephp-pear if it’s already not installed. apt-get install php-pear
Then install following PEAR packages

  • pear install mail
  • pear install Net_SMTP
  • pear install Auth_SASL
  • pear install mail_mime

Then install POSTFIX

apt-get install postfix

This command will bring dialogue step by step to setup mail server.

Select Internet Site

and choose domain mail to be sent from

Try to send mail using mail() function, and you’ll receive the one you sent.

Change/Add virtualhost name like localhost

Follow the steps below to add/change the virtualhost name:

For Windows

  1. Go to your xampp folder: C:\xampp\apache\conf\extra
  2. Find httpd-vhosts.conf and open it with any of text editor like notepad
  3. Stop Xampp if running.
  4. Add these line first: 
    1. NameVirtualHost *:80
    2.  
    3. <VirtualHost *:80>
    4. DocumentRoot "C:/xampp/htdocs"
    5. ServerName localhost
    6. </VirtualHost>
  5. Then: 
    1. <VirtualHost *:80>
    2. DocumentRoot "C:/xampp/htdocs/your/website/folder"
    3. ServerName yourdesiredname.you
    4. ServerAlias www.yourdesiredname.you
    5. <Directory "C:/xampp/htdocs/your/website/folder">
    6. AllowOverride All
    7. Require all Granted
    8. </Directory>
    9. </VirtualHost>
  6. Save the file
  7. Now go to : C:\Windows\System32\drivers\etc
  8. Find for hosts
  9. make a back up of this file to anywhere on your system
  10. Now open the file with any of text editor like notepad
  11. Add these lines to the end of the file: 
    1. 127.0.0.1 localhost
    2. 127.0.0.1 www.yourdesiredname.you
  12. Save the file
  13. Restart the xampp
  14. write your chosen domain name i. e. : www.yourdesiredname.you into your browser and you are done