Php – New CentOS 7 server – Sending mail from a PHP application

centos7configurationemailPHPsmtp

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)


--0AEF.1434711105/testserver1.localdomain
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

--0AEF.1434711105/testserver1.localdomain
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

--0AEF.1434711105/testserver1.localdomain--

Best Answer

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.