Apologies for the newbie question but i'm hoping someone can provide me with some help/steps.

I am in the process of migrating a website from a managed shared hosting account online to a new CentOS 7 cloud server. Everything seems to be working perfectly apart from when it tries to send emails from the PHP scripts. When setting up the CentOS server I did not configure any mail apps etc..

I am assuming this is because I haven't installed something. Would anyone be able to advise how I can set up the server to send emails from the PHP app (I do not want to setup a full mail server as this is managed through Office365).

I tried sending a test and all it does it post a message to me in /var/spool/mail

Any help/advice would be great! (Output from /var/spool/mail/ below)

Content-Description: Delivery report
Content-Type: message/delivery-status

Reporting-MTA: dns; testserver1.localdomain
X-Postfix-Queue-ID: 0AEF
X-Postfix-Sender: rfc822; apache@testserver1.localdomain
Arrival-Date: Fri, 19 Jun 2015 06:51:44 -0400 (EDT)

Final-Recipient: rfc822; chris@gmail.com
Action: failed
Status: 5.0.0
Remote-MTA: dns; googlemail.com
Diagnostic-Code: smtp; 550-Verification failed for
    <apache@testserver1.localdomain> 550-The mail server could not deliver mail
    to apache@testserver1.localdomain.  The account or domain may not exist,
    they may be blacklisted, or missing the proper dns entries. 550 Sender
    verify failed

Content-Description: Undelivered Message
Content-Type: message/rfc822

Return-Path: <apache@testserver1.localdomain>
Received: by testserver1.localdomain (Postfix, from userid 48)
    id 0AEF; Fri, 19 Jun 2015 06:51:44 -0400 (EDT)
To: chris@gmail.com
Subject: My subject
X-PHP-Originating-Script: 0:index.php
Message-Id: <0AEF@testserver1.localdomain>
Date: Fri, 19 Jun 2015 06:51:44 -0400 (EDT)
From: apache@testserver1.localdomain (Apache)

First line of text
Second line of text


You'll still need to configure something to deal with email.

The easiest way is probably to configure whatever MTA you're using so that it changes apache@testserver1.localdomain (the email address that php ends up using) into whatever mail address you want to use.

Since you seem to be using Postfix, you should check out this part in the official Postfix documentation which explains how to do that.

  • Hi Wouter, thank you for the quick response. I followed the instructions on the page you suggested and tried again but still no luck. Im new to this so im not certain I have done it correctly
    – rosey85uk
    Jun 19 '15 at 11:27
  • Please explain what exactly you did and how it failed. Can't expect help if you don't show what you're doing. Jun 19 '15 at 11:37
  • I edited the /etc/postfix/main.cf file to contain smtp_generic_maps = hash:/etc/postfix/generic. I then editing the /etc/postfix/generic file and added in the local address it was using and supplied the correct one EG. his@localdomain.local hisaccount@hisisp.example I then saved the files and ran postmap /etc/postfix/generic Do I need to have a domain pointing to the server before doing this? At the moment it just has is public IP as provided by the cloud provider.
    – rosey85uk
    Jun 19 '15 at 11:43
  • You don't necessarily need a domain pointing to the server. However, your server must be allowed to send mail from the domain that you're using. That is, the domain must exist, and the domain must not have an SPF record (or if it does, the server must be listed as one of the permitted senders). Otherwise your mail is likely to be dropped by the receiving server as spam. Jun 23 '15 at 13:13

Wouter is correct to say that you need an mta, and that postfix is a good choice, however before spending a lot of time configuring it, you should check that your efforts will not be in vain.

  • can your server resolve hostnames (try with nslookup)?
  • can it make connections to the outside world on port 25 (try with telnet)?
  • is selinux enabled?

Disabling selinux might seem a bit clumsy and ill-advised but, while the RH7 type policy is an improvement on 6.5, SElinux and the RH policy are truly horrible and add very little security benefit at a horrendous cost in terms of effort on anything other than a static content server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.