?
Solved

Configure mail

Posted on 2004-11-05
28
Medium Priority
?
325 Views
Last Modified: 2010-04-20
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?
0
Comment
Question by:x_terminat_or_3
  • 14
  • 13
28 Comments
 
LVL 7

Expert Comment

by:troopern
ID: 12507307
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
 
LVL 40

Expert Comment

by:jlevie
ID: 12507384
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
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12507527
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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 40

Expert Comment

by:jlevie
ID: 12507752
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
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12507837
how can I change this?
0
 
LVL 40

Assisted Solution

by:jlevie
jlevie earned 2000 total points
ID: 12507965
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
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12508000
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
 
LVL 40

Assisted Solution

by:jlevie
jlevie earned 2000 total points
ID: 12509054
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
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12509151
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
 
LVL 40

Assisted Solution

by:jlevie
jlevie earned 2000 total points
ID: 12509185
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
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12509215
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
 
LVL 40

Assisted Solution

by:jlevie
jlevie earned 2000 total points
ID: 12509777
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
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12511746
ok.  I think I understand but where do I set the hostname?
0
 
LVL 40

Expert Comment

by:jlevie
ID: 12511753
What Linux are you running?
0
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12511763
Fedora test 3
0
 
LVL 40

Assisted Solution

by:jlevie
jlevie earned 2000 total points
ID: 12513919
The hostname is set at boot by what HOSTNAME is set to in /etc/sysconfig/network
0
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12514131
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
 
LVL 40

Assisted Solution

by:jlevie
jlevie earned 2000 total points
ID: 12514376
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
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12517367
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
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12517475
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
 
LVL 40

Assisted Solution

by:jlevie
jlevie earned 2000 total points
ID: 12517783
After the last round of config changes did you restart both Apache & Sendmail (or reboot)?
0
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12518102
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
 
LVL 40

Assisted Solution

by:jlevie
jlevie earned 2000 total points
ID: 12518489
> 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
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12518717
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
 
LVL 40

Accepted Solution

by:
jlevie earned 2000 total points
ID: 12518906
> 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
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12526383
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
 
LVL 40

Assisted Solution

by:jlevie
jlevie earned 2000 total points
ID: 12527175
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
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12527723
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month16 days, 9 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question