user702300
user702300

Reputation: 1241

Google Apps: Not receiving email from same domain sent by PHP mail()

For testing the email sent by PHP mail() I have the following script called phpmail.php

<?php

$to      = "[email protected] [email protected] [email protected]";
$header  = "From: [email protected]";
$subject = "Testing PHP email from domain.com";
$body    = "This is sent form the server.";

if (mail($to, $subject, $body, $header)) {
    echo("Message successfully sent!");
} else {
    echo("Message delivery failed...");
}

?>

it sends to 3 email addresses:

  1. [email protected] (Google Apps)
  2. [email protected] (standard Gmail)
  3. [email protected] (Also Google Apps)

the script is run from the server hosting the "domain.com" website. While the same message is received by emails 2. and 3., it's not by 1. which is the same domain where PHP was executed.

Is there something I need to change from the server to make it work? Thank you.

Edit: The MX is setup correctly using instructions from

https://support.google.com/a/answer/174125?hl=en

I have another server using this settings and it's working correctly. For some reason, it's not working with this server. I believe (fuzzy memory) it worked some time ago.

Upvotes: 0

Views: 2066

Answers (2)

user702300
user702300

Reputation: 1241

Solved the issue by changing the network hostname (it was same as the Google Apps) to something else following instruction from this site:

http://www.rackspace.com/knowledge_center/article/centos-hostname-change

Upvotes: 1

DerLola
DerLola

Reputation: 3918

Are you running the first Google Apps domain on the same domain as the website is hosted? It is likely that your server is configured to recognize 'internal' mail. If this is the case, the mail is delivered to the local mailserver instead of the Google Apps mailserver.

The solution is to configure the DNS (specifically MX) records of your (web) server to point to Google Apps. This can be done easily if you have a control panel like DirectAdmin or Plesk. If not, Google specific instructions for your setup.

Upvotes: 0

Related Questions