Configure mail

HI all


When I try to send mail with the php send command it bounces.


Reason: my isp does not accept incomming mail from apache@localuser.localhost or something like that

Can I change this setting somewhere?
LVL 2
x_terminat_or_3Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

troopernCommented:
You can change the PHP script to edit the FROM tag in the mailheader I think.
Somehting like:
<?
mail("user@domain.tld", "Test MAIL", "Test Mail", "From: Name <user@domain.tld>");
?>

Probably your ISP is set to only allow sends to/from FQDN's
0
jlevieCommented:
At this point we don't know if your ISP is objecting to the envelope sender address (apache@localhost.localdomain), ow whether they object to the hostname offered in the SMTP connection (localhost.localdomain). To fix the envelope sender issue you can set the from address in the mail() call in PHP, something like:

mail("nobody@example.com", "the subject", $message, "From: webmaster@$SERVER_NAME\r\n",
          "-fwebmaster@$SERVER_NAME");

To solve the hostname issue you'd need to configure your server with a valid hostname. In the case of an ISP customer the machine may need to have the hostname that a reverse lookup of your IP returns. Some ISP's aren't as picky and any valid hostname will work. Of course it should be a hostname in a domain you own.
0
x_terminat_or_3Author Commented:
yeah but the thing is, here is the script I use:

  $to=$where;
  $subject="message title";
  $message="messagebody";
  $headers  = "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
  /* additional headers */
  $headers .= "To: $where\r\n";
  $headers .= "From: Inschrijvingsrobot www.vlaamse-kern.com\r\n";
  $headers .= "Return-Path: Webrobot@vlaamse-kern.com\r\n";
  $headers .=  "Reply-to: webmeester@vlaamse-kern.com\r\n";
  /* and now mail it */
  $res=mail($to, $subject, $message, $headers);


As you can see, the string "apache" or "localuser" or "localdomain" is not here.  So where does it come from?  Where can it be changed?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

jlevieCommented:
Because you don't explicity set the envelope sender (-fInschrijvingsrobot www.vlaamse-kern.com) in the mail() call the current user (apache) and what 'hostname' returns (localhost.localdomain) will be automatically used.
0
x_terminat_or_3Author Commented:
how can I change this?
0
jlevieCommented:
Changing the machine's network configuration to give it a valid hostname will change that part. However the mail will then appear to be from apache@host.dom.tld (if hostname returns host.dom.tld). Only by changing the PHP code or the user that the web server runs as will you be able to change apache to something else.
0
x_terminat_or_3Author Commented:
I found it!  I changed it in network properties on host aliases!


But how come it takes almost a minute for the sendmail to execute itself?
0
jlevieCommented:
That sounds a reverse lookup problem and would indicate that the network config of the machine isn't correct.  Since this machine is a web server it presumably has a static IP. That means that the hostname would be set to either be what a reverse lookup of it's IP is, or a hostname within a domain that you own. Along with that hostname setting you need to have a /etc/hosts file that looks like:

127.0.0.1       localhost.localdomain localhost
123.4.5.6       my-web.my-dom.tld my-web

Network servers (like Sendmail and Apache) need to be restarted after this change, or you can just reboot.
0
x_terminat_or_3Author Commented:
It does have a fixed IP

81.xxx.xxx.168.250

I have a registered domain www.mydomain.com but my isp hasn't linked it to my fixed ip yet.  

so my /etc/hosts file should look like what:

127.0.0.1  localhost.localdomain localhost
81.xxx.xxx.168.250  what do I fill here?

0
jlevieCommented:
127.0.0.1  localhost.localdomain localhost
81.x.x.168.250  www.mydomain.com www

If that's what you've set hostname to return.
0
x_terminat_or_3Author Commented:
but what do you mean if that's what I've set hostname to return.


Sorry if I ask so much, but I have 0 exp with linux.  I'm a bit misformed after 14 years of commercial software (read ms) ;-)



Ramses
0
jlevieCommented:
You've set the hostname of the system, but something like sendmail will see a connection from an IP. Sendmail will then attempt to do a reverse lookup on that IP to see what hostname is associated with the IP. If the requisite data isn't in the hosts file it will try a DNS lookup which will timeout in about 60 seconds if the data isn't available. By ensuring that /etc/hosts contains the IP and what you've set the host name to Sendmail can do a local (fast) lookup.
0
x_terminat_or_3Author Commented:
ok.  I think I understand but where do I set the hostname?
0
jlevieCommented:
What Linux are you running?
0
x_terminat_or_3Author Commented:
Fedora test 3
0
jlevieCommented:
The hostname is set at boot by what HOSTNAME is set to in /etc/sysconfig/network
0
x_terminat_or_3Author Commented:
So, I try to send mail with the server (to test) right.

This is my hosts file:

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1      localhost.localdomain      localhost
81.xx.168.250      ramses      mydomain.com

In all logic, when I connect (on the sever) to the server by typing its IP in the addressbar of the browser, and then try to sendmail trough php, the IP that sendmail sees is the 81.xx.168.250 right, and that one's in the hosts file so it shouldn' t time out... but it does!
0
jlevieCommented:
If that's what's in your hosts file it is wrong and will cause reverse lookup timeouts. The correct form would be:

81.xx.168.250     ramses.mydomain.com ramses

Provided that ifconfig shows 81.xx.168.250 as the IP of your network connection. If you have the machine behind a firewall it is most likely using an IP in one of the private networks and that's what should be in the hosts file, not the public IP.
0
x_terminat_or_3Author Commented:
why does it have to say ramses.mydomain.com ?  


Anyway, I did what you said and STILL it takes two minutes just to send the message.

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1      localhost.localdomain      localhost
81.xx.168.250      ramses.mydomain.com ramses
0
x_terminat_or_3Author Commented:
Here are the headers of a message I sent via the php script

X-Apparently-To: xxxxxxxxxxxxxx@yahoo.fr via 216.xxx.yyy.99; Sun, 07 Nov 2004 07:06:33 -0800
X-Originating-IP: [81.xx.168.250]
Return-Path: <apache@mydomain.com>
Received: from 81.xx.168.250  (EHLO mydomain.com) (81.220.168.250) by mta103.mail.sc5.yahoo.com with SMTP; Sun, 07 Nov 2004 07:06:33 -0800
Received: from mydomain.com (localhost.localdomain [127.0.0.1]) by mydomain.com (8.13.1/8.13.1) with ESMTP id iA7EpnB8014873 for <xxxxxxxxxxxxxx@yahoo.fr>; Sun, 7 Nov 2004 15:53:04 +0100
Received: (from apache@localhost) by mydomain.com (8.13.1/8.13.1/Submit) id iA7Epin3014862; Sun, 7 Nov 2004 15:51:44 +0100

0
jlevieCommented:
After the last round of config changes did you restart both Apache & Sendmail (or reboot)?
0
x_terminat_or_3Author Commented:
I DID!

Tell me, when I stop the sendmail service, and then try to sendmail trough the php script, it executes instantly, but when looking in the log, it get's refused.  Should sendmail be configured to start as a service with the system?

Here is the log

Nov  7 18:51:54 ramses sendmail[5224]: iA7Hpso0005224: from=apache, size=1405, class=0, nrcpts=1, msgid=<200411071751.iA7Hpso0005224@ramses.mydomain.com>, relay=apache@localhost
Nov  7 18:51:54 ramses sendmail[5224]: iA7Hpso0005224: to=xxxxxxxxxx@yahoo.fr, ctladdr=apache (48/48), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=31405, relay=[127.0.0.1] [127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
0
jlevieCommented:
> Should sendmail be configured to start as a service with the system?

Yes. And the errors in the maillog suggest that either the smmsp Sendmail process isn't running or that the access map doesn't include the localhost IP as allowd to relay. The default content of the access map should include:

# by default we allow relaying from localhost...
localhost.localdomain           RELAY
localhost                       RELAY
127.0.0.1                       RELAY
                                                                               
If in doubt, execute a '/sbin/service sendmail stop' followed by a '/sbin/service sendmail start'
0
x_terminat_or_3Author Commented:
jlevie, this is getting heavy....

Can you tell me how to setup the system?
what should be in php.ini (for the sendmail) ?
how should I configure apache (for the sendmail) ?
how should I configure sendmail ?

Maybe this approach will be easier instead of trying to find an error.
0
jlevieCommented:
> Can you tell me how to setup the system?

/etc/sysconfig/network needs to include:

HOSTNAME=ramses.dom.tld

/etc/hosts needs to contain:

127.0.0.1              localhost.localdomain localhost
81.xx.168.250     ramses.dom.tld ramses

replacing "81.xx.168.250 " and "dom.tld" with the actual data.

The stock sendmail.mc for Fedora is fine as is the stock php.ini. Likewise, nothing special is needed in the Apache config for mail to work. With the possible exception of making sure that /etc/httpd/conf/httpd.conf has the ServerName directive commented out.

You will need to ensure that /etc/mail/access contains:

# by default we allow relaying from localhost...
localhost.localdomain           RELAY
localhost                       RELAY
127.0.0.1                       RELAY

And /etc/mail/local-host-names needs to include:

localhost.localdomain
localdomain
ramses.dom.tld
dom.tld

If this server is to receive mail you'll need the MX for the domain pointing to ramses.dom.tld and you'll need to comment out the localhost restriction in /etc/mail/sendmail.mc.

Depending on whether you are hosting multiple domains there may be other things that need to be set up in the mail configuration.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
x_terminat_or_3Author Commented:
jlevie

Tell me.  I did do these settings, but I found out that it's not  a www domain name.  My domain is not www.mydomain.com but just http://mydomain.com

When I go in my browser and type http://mydomain.com/   I come at my site, but when I click a relative link it's going to www.mydomain.com




0
jlevieCommented:
If you name the machine ramses.mydomain.com the DNS should have the MX record pointing to that hostname and an A record for that hostname pointing to 81.xx.168.250. It is common to also have a CNAME record for www.mydomain.com pointing to ramses.mydomain.com and to also equate mydomain.com to 81.xx.168.250. That allows http://mydomain.com & http://www.mydomain.com to both go to the same place. And, strictly speaking, there should be a PTR record for 81.xx.168.250 pointing to ramses.mydomain.com.

If you are only hosting a single domain and ServerName is commented out in httpd.conf and you don't otherwise mention a hostname in httpd.conf those DNS settings will result in everything working like you'd expect.
0
x_terminat_or_3Author Commented:
Thank you for your help jlevie.  Maybe it's not working because my isp didn't made the MX stuff yet.  I mean, I don't control those things.  I said to my isp I want that domain and point it to that IP.  But he only created the domain up to now...


Anyway, Thank you for your continued input.



With kind regards



Ramses (x_terminat_or_3)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.