Therefore if the responsible mailserver for a given domain is not installed on the same server the mail will be rejected by most recipients. Two possible solutions exist:
- You can add the webserver as an additional authorized mail server…
- … or configure sendmail to relay mails through your already working mailserver.
I always choose option 2, as it’s easier to configure and maintain. You only have to have a valid SMTP user for the existing mailserver and root access to the webserver. The following steps show how to set mail relaying up:
Before we can start we have ensure, that sendmail is installed. This can be running the following command:
If it is installed the full path to the executable will be printed. Otherwise you can install it using your distributions’s package manager. On Debian-style distributions you can use the following command:
sudo apt-get install sendmail
The installation can take quite some time on slow internet connections.
Configure relay credentials
Now we have to configure the mailserver and the corresponding user credentials. This is done by appending the following line to /etc/mail/authinfo using your favorite text editor.
AuthInfo:your_mail_server.your_domain.tld "U:your_username" "P:your_password"
You have to replace the dummy information.
Updating the sendmail configuration
This step updates the sendmail configuration to include the previously added server credentials. Add the following lines in the file /etc/mail/sendmail.mc after the “FEATURE(`access_db’, , `skip’)dnl” directive.
FEATURE(`authinfo',`hash /etc/mail/authinfo') define(`SMART_HOST', `your_mail_server.your_domain.tld')
Replace the hostname!
Saving the configuration
Use the following commands to save the configuration. After that you should be able to send mails through PHP.
cd /etc/mail/ sudo makemap hash authinfo < authinfo sudo m4 sendmail.mc >sendmail.cf sudo /etc/init.d/sendmail restart