4

Hello I have tried these command but I am not able to send mail please help me out..

1) Install sendmail

Sendmail might already be installed, but just in case, enter this into the server terminal:

sudo apt-get install sendmail

2) Configure sendmail

Enter the following command into the terminal and type "Y" for each question it asks:

sudo sendmailconfig

3) Edit hosts file

Time to edit your server's hosts file, access it by entering the following command into the terminal:

sudo vim /etc/hosts

Add the following line to the top of the file and save it:

127.0.0.1 localhost localhost.localdomain your_domain_name_here.com

Comment out any duplicate lines that already existed.

4) Restart apache Let's restart your server just for good measure. At this point emails sent via PHP's mail() function should be sending successfully and without much delay.

sudo service apache2 restart 

I didn't understand the 3rd step because I am working on localhost so how I can add domain name here..

Any help will be appreciable

PRashant PUrohit
  • 380
  • 1
  • 3
  • 21
  • You faced issues with restarting apache? Do elaborate. – apokryfos Apr 08 '16 at 08:52
  • sorry i apologize i edited my question now I got confused on 3rd setp – PRashant PUrohit Apr 08 '16 at 08:54
  • Are you not able to send mail or do the mails not arrive? The last one is impossible to avoid when you send from your local computer; it will probably not pass any of the (spam)filters on the way to its destination. – jeroen Apr 08 '16 at 08:57
  • I still don't understand what the issue you faced is. You've edited the `/etc/hosts` file and added additional domains resolving to `127.0.0.1` and that looks fine. You should now be able to access your localhost via those additional domains as well. – apokryfos Apr 08 '16 at 09:11
  • Sir I got confused what should i do "127.0.0.1 localhost localhost.localdomain your_domain_name_here.com" what should i replace with your_domain_name_here.com, – PRashant PUrohit Apr 08 '16 at 09:12
  • 1
    `your_domain_name_here.com` is applicable if you want to set-up a virtual host. Check [this tutorial](https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts) for clarification. Point is, if you want to access your own website via e.g. `www.my.virtual.host.com` you'll have to add the `127.0.0.1 www.my.virtual.host.com` line in your `/etc/hosts` file. If you don't need a virtual host then you could just ignore that last part of that line. – apokryfos Apr 08 '16 at 09:15
  • not getting mail sir would you like to see my host file – PRashant PUrohit Apr 08 '16 at 09:49

2 Answers2

3

your_domainname_here is used for virtual host . So if you are not creating virtual host simply run this command

sudo vim /etc/hosts

and add

127.0.0.1 localhost localhost.localdomain

restart your server

service apache2 restart

hope it will help you

Bijren
  • 41
  • 3
0

To send email through Gmail from localhost please check PHP+Ubuntu Send email using gmail form localhost is possible another answer.

Vikas Dwivedi
  • 5,233
  • 1
  • 21
  • 16