In order to send e-mail from the websites, we need to install a mailserver. Since we only want to send e-mails, we can use a send-only mailserver.
apt-get install postfix
During the configuration select the configuration for Internet Site
. The system’s mail name should be a valid FQDN (also located in /etc/mailname
).
Open the Postfix configuration file
nano /etc/postfix/main.cf
and check if the fields myhostname
and mydestination
also have a correct FQDN. The hostname should be a single hostname, the destination can consist of multiple entries (some remote, others local).
If the Postfix configuration was changed, the service should be restarted:
service postfix restart
To test if you can send e-mails from the website you can use the following PHP-script:
<?php
$to = "[email protected]";
$subject = "Mail test";
$message = "This is a test";
$headers = "From: [email protected]\r\n";
if (mail($to, $subject, $message, $header))
echo "OK: Mail sent to " . $to;
else
echo "ERROR: Could not send mail to " . $to;
?>
Possible problems
550 Access denied - Invalid HELO name: Make sure the field myhostname
in /etc/postfix/main.cf
contains a fully qualified domain name. Thus myserver.example.com
not just myserver
.