Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple mail() function problem

Status
Not open for further replies.

awingnut

Programmer
Feb 24, 2003
759
US
I'm trying to build a plain text email in a PHP script. I've done this successfully in another script but this new one fails and I need some help figuring out how to debug it. The crux of the problem is that the local mailer rejects the message saying there is no receipient. When I look at the bounced message, there most certainly is a receipient and it is valid. The error must be talking about something else but I can't figure out what. Here is the code segment:
Code:
$sendto="myuserid@mydomain.com";
$headers="From: someone@mydomain.com\r\n";
$headers.="Date: ".date("m/d/Y")."\r\n";
$headers.="CC: someoneelse@mydomain.com\r\n";
$headers.="Content-type: text/plain\r\n");
$subject="Test message from PHP";
$body="blah blah blah";
mail($sendto,$subject,$body,$headers);
Can anyone see what I'm doing wrong or suggest a debug technique? TIA.
 
Thanks for the reply.

Isn't the first argument to mail supposed to be that? Anyway, it made no difference. I now can see 2 'To:' headers in the bounced mail. This is bizzare and frustrating. I cannot see any difference, logically, between the one that works and this one.
 
Yes. The Unix 'mail' command works fine. I'm thinking maybe there is a problem with the PHP function itself. I'm going to try a server running Apache and see if it works there.
 
I also saw this in the user-supplied comments on the PHP online manual entry for mail():

If you're using a linux server using Postfix, and your server hasn't the host name set to a valid name (because it's behind a firewall in an intranet), it's possible that when sending mails using the mail function, some mail servers reject them. This is because they can't check the return path header. If you want to change the Return-Path used by sendmail init the php.ini and edit the sendmail_path variable to this:

sendmail_path = "sendmail -t -i -F webmaster@yoursite.com -f webmaster@yoursite.com"

Maybe you need to explicitly set a Return-Path header.



Want the best answers? Ask the best questions! TANSTAAFL!
 
The error message is:

No recipients specified.

The Apache server worked fine. It must be a problem with the PHP implementation on that server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top