Preventing sendmail from been very slow
The first thing that I did after installing sendmail with
aptitude install sendmail
is I put “gate.localhost” (gate is my server name) to /etc/hosts so it looks like this:
127.0.0.1 localhost.localdomain localhost 127.0.1.1 gate.localhost gate # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters
With default /etc/hosts containing only “gate” and “localhost” sendmail hangs up for a while and writes to /var/log/mail.log the following message:
My unqualified host name (gate) unknown; sleeping for retry.
To test how sendmail works I used the following command:
/usr/sbin/sendmail -t -f email@example.com -v -i < body.txt
Where body.txt is a text file containing the message body:
Subject: test mail to Some Address! From: Me <firstname.lastname@example.org> To: Vasya<email@example.com> first line of my message
Please note, that without –f option provided in command line sendmail would not work, saying that there are some problems with the sender address.
Configuring SMTP server settings
To make sendmail work via my SMTP server I added SMART_HOST directive to sendmail.mc:
Then I executed the following commands to changes take effect:
cd /etc/mail m4 sendmail.mc > sendmail.cf make /etc/init.d/sendmail restart
Fortunately, my SMTP server does not require any authorization so I do not need to use AuthInfo directive.
Configuring PHP mail() function
At last I put the following to /etc/php5/apache2/php.ini:
; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path sendmail_path = "/usr/sbin/sendmail -t -f firstname.lastname@example.org -i"
I feel that there is another way, but looks like my php mail() function now works fine, at least I can receive messages from my websites.