LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   PHP + Sendmail problem (https://www.linuxquestions.org/questions/linux-newbie-8/php-sendmail-problem-460610/)

ArthurDent 07-03-2006 12:36 PM

PHP + Sendmail problem
 
Hi All,

I'm trying to get PHP to send mail to the outside world - which I might need to do one day if I decide to open up my webserver to the net...

This is my little testing script:
Code:

<?php
$fd = popen("/usr/sbin/sendmail -t","w");
fputs($fd, "To: someone@a.real.address.com\n");
fputs($fd, "From: Me \n");
fputs($fd, "Subject: Test message from my web site\n");
fputs($fd, "X-Mailer: PHP3\n");
fputs($fd, "Testing.\n");
pclose($fd);
?>

When I run it it fails with the following error:
Code:

Date: Mon, 3 Jul 2006 17:35:35 +0100
From: Mail Delivery Subsystem <MAILER-DAEMON@localhost.localdomain>
To: <apache@localhost.localdomain>
Subject: Returned mail: see transcript for details
Auto-Submitted: auto-generated (failure)

[-- Attachment #1 --]
[-- Type: text/plain, Encoding: 7bit, Size: 0.6K --]

The original message was received at Mon, 3 Jul 2006 17:35:33 +0100
from ArthurDent [127.0.0.1]

  ----- The following addresses had permanent fatal errors -----
<someone@a.real.address.com>
    (reason: 550-Verification failed for <apache@localhost.localdomain>)

  ----- Transcript of session follows -----
... while talking to punt-1.mail.demon.net.:
>>> DATA
<<< 550-Verification failed for <apache@localhost.localdomain>
<<< 550-Unrouteable address
<<< 550 Sender verify failed
550 5.1.1 <someone@a.real.address.com>... User unknown
<<< 503 valid RCPT command must precede DATA

[-- Attachment #2 --]
[-- Type: message/delivery-status, Encoding: 7bit, Size: 0.4K --]

Reporting-MTA: dns; localhost.localdomain
Received-From-MTA: DNS; ArthurDent
Arrival-Date: Mon, 3 Jul 2006 17:35:33 +0100

Final-Recipient: RFC822; someone@a.real.address.com
Action: failed
Status: 5.1.1
Remote-MTA: DNS; punt-1.mail.demon.net
Diagnostic-Code: SMTP; 550-Verification failed for <apache@localhost.localdomain>
Last-Attempt-Date: Mon, 3 Jul 2006 17:35:35 +0100

If I replace "someone@a.real.address.com" with "myusername@localhost.localdomain" the mail finds its way into my user's mail spool.

I have Googled without much success. The closest I have come to a solution was reading somewhere that I should have something in my /etc/mail/local-host-names file so I have tried both "localhost.localdomain" and "apache@localhost.localdomain" (there is no example of what form the entry should take) and in any case - it didn't work (I did re-start Apache before I tried again...)

Is it a sendmail problem? Is it a PHP problem? Is it an Apache problem?
Can anyone guide me through this?

Many thanks to all...

Mark

btmiller 07-03-2006 01:49 PM

It looks to me like the recipient's e-mail server rejected the message because it's from an obviously bogus e-mail address (apache@localhost.localdomain). You should give your machine a valid host name if you want to do this for real (if you've not got a static IP dyndns or no-ip can help).

Also, it's much simpler to use PHP's in-built mail function for this. IIRC you can use this to set the From address to whatever you want, so mnaybe you won't have to bother with the host name. Be advised, though, some mail servers flag messages with host names that don't match the originating server as spam, though.

ArthurDent 07-03-2006 02:17 PM

Quote:

It looks to me like the recipient's e-mail server rejected the message because it's from an obviously bogus e-mail address (apache@localhost.localdomain).
Well the recipient is me. I've checked the headers and I don't think the message even gets close to getting out into the big wide world. It gets rejected before it goes to my ISP (I think).
Quote:

You should give your machine a valid host name if you want to do this for real (if you've not got a static IP dyndns or no-ip can help).
How do I do this. I don't (yet) have a real web address and so my machine is named (ahem) ArthurDent.

However. I do think you are on to something here because when I restart Apche I get the following error:
Code:

[root@ArthurDent ~]# /sbin/service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                          [  OK  ]
[root@ArthurDent ~]#

How do I go about fixing this?

Thanks again...

Mark


All times are GMT -5. The time now is 12:40 PM.