2

I am trying to send an email to my thunderbird or google acount using PHP from a local server in Ubuntu. I have used the mail() function in PHP.

I have done some research and apparently you can not send an email from the local server unless you install an email system. So I went with postfix and installed it:

sudo apt-get install postfix

For the configuration I chose Satellite. I don't know how to proceed from here.

What should I type for System mail name, is localhost correct?

I left SMTP relay host and Root and postmaster mail recipient: blank.

I am very much confused and could not find any step by step tutorial. I would appreciate any help and some clarification on how to finish the steps in postfix configuration.

Edit: I looked at this https://help.ubuntu.com/community/Postfix

But why System mail name: example.com and why we choose General type of mail configuration: Internet Site?

Jack
  • 161
  • 7
  • because localhost is not recognisable on the internet as it is local name; as for Internet Site - that is standard configuration for standalone machine that wants to communicate with the outside – Marek Bettman Sep 15 '15 at 13:38
  • This can help: http://askubuntu.com/questions/47609/how-to-have-my-php-send-mail – Parto Sep 15 '15 at 13:38

1 Answers1

0

In short: choose Internet Site as a configuration and use fqdn for Mail System name (if you use localhost it will be classified as spam most likely).

Problem is, for some of the mail servers nowadays it will not be enough (for example, gmail tends to classify such configuration as spam).

What else will you need:

  • MX DNS record (a DNS record, that will point to appropriate IP as a Mail target for given domain - you can check it with host -t MX domain)
  • postconf -e "myhostname = [hosts fqdn]"
  • postconf -e "myorigin = \$myhostname"
Marek Bettman
  • 461
  • 3
  • 10
  • You can do much more in term of configuration, but I've found out that that was the bare minimum for my LAMP stack to send mail via mail() correctly. – Marek Bettman Sep 15 '15 at 13:39
  • Thanks, would it work for both gmail and thunderbird? – Jack Sep 15 '15 at 13:41
  • What do you mean - gmail is a mail service, thunderbird is just email client. Thunderbird will work with any IMAP service. If you will see emails in gmail interface, then Thunderbird will work :) – Marek Bettman Sep 15 '15 at 13:44
  • The thing is I get an email as www-data@example.com in my gmail account using mail() function of php but when I change the email address to my company's email address which is set-up using windowslivemail (I get my emails through thunderbird in ubuntu) I don't see anything. – Jack Sep 15 '15 at 15:58
  • Yeap, totally correct - you don't want to anybody be able to spoof author like this. So generally most mail servers won't allow an email originating from one domain if from header disagrees. BUT, you can configure your postfix as a relay and tell it to authenticate with your work email which will have effect of emails seem to be originating from your work email. – Marek Bettman Sep 15 '15 at 16:58
  • I have typed postconf -e "myhostname = [hosts fqdn]" and postconf -e "myorigin = \$myhostname" ...and now I can not even get an email in my gmail :( – Jack Sep 17 '15 at 17:14
  • ANy idea of how to undo this? – Jack Sep 17 '15 at 17:15
  • hmmm ... you did substitute `[hosts fqdn]` with proper fqdn, right? can you paste the contents of /etc/postfix/main.cf ? – Marek Bettman Sep 17 '15 at 17:36
  • no I have just copy pasted it, what is the proper fqdn? – Jack Sep 17 '15 at 17:47
  • mtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination myhostname = [hosts fqdn] alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases mydestination = localhost, localhost.localdomain, localhost, example.comserver1.example.com, example.com, localhost.example.com, localhost relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all inet_protocols = all myorigin = /etc/mailname – Jack Sep 17 '15 at 17:48
  • I guess fqdn is the hostname of my computer right? – Jack Sep 17 '15 at 17:55
  • got it I have typed hostname --fqdn I am am going to change it now – Jack Sep 17 '15 at 17:57
  • FQDN is Fully Qualified Domain Name (https://en.wikipedia.org/wiki/Fully_qualified_domain_name) - in simple terms [hostname].[domainname], for example: mail.domain.com. It doesn't have to be your machine name, but it has to be the name where MX records for your domain point. And it should be added to /etc/hosts as well (to the line with your external IP, not 127.0.0.1 or 127.0.1.1) – Marek Bettman Sep 17 '15 at 17:57
  • just don't change it to localhost :) – Marek Bettman Sep 17 '15 at 17:58
  • also, `mydestination` should contain your domain and probably NOT contain the stuff with *example.com (unless you own example.com :)) – Marek Bettman Sep 17 '15 at 18:00
  • ok thanks I will fix them and will let you know if it works out! – Jack Sep 17 '15 at 18:14
  • Still not working. I – Jack Sep 17 '15 at 18:28
  • smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination myhostname = [mary] alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases mydestination = localhost, mary, localhost.localdomain, localhost, radar.com relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all inet_protocols = all myorigin = $mary – Jack Sep 17 '15 at 18:29
  • For my destination should I put the part before .com of my windowslive work email? – Jack Sep 17 '15 at 18:30
  • Maybe I should download dovecot – Jack Sep 17 '15 at 18:31