×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Bad header=No recipient addresses found

Bad header=No recipient addresses found

Bad header=No recipient addresses found

(OP)
I've recently moved servers and now a piece of PHP script is no longer working properly.

I pulls a bunch of e-mail addresses from a MySQL database and then sends them all a "group" e-mail. Except it only sends the e-mails to some (almost all) of the e-mail address and then comes up with this screen:

CODE

500 Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@mydomain.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request. [/quote]

Looking in the web error logs brings up this message:
[code]"malformed header from script. Bad header=No recipient addresses found"

I've checked the e-mail addresses back and forth (in this instance there's 65) and I can't see any which are the wrong format.

Here is the script:

CODE

$to = $email; <=$email directly from MySQL database
    $mailheaders = "From: $sender_name <$sender_email>\n";
    $mailheaders .= "Reply-To: $sender_email\n\n";
    mail($to, $subject, $msg, $mailheaders);

Any ideas on what's going wrong?

Cheers
Tama

I do my sums on fingers and thumbs.

RE: Bad header=No recipient addresses found

On this new system, is PHP running as a web server module, or as a CGI language?

Want the best answers? Ask the best questions!

TANSTAAFL!!

RE: Bad header=No recipient addresses found

(OP)
It's an Apache/Linux box and PHP is running as "PHP Hypertext Preprocessor for Apache"

Is that the info you were after?

Cheers
Tama

I do my sums on fingers and thumbs.

RE: Bad header=No recipient addresses found

No really.

PHP can run as a standalone interpreter which Apache invokes as a CGI.  PHP can also run as an Apache module.

For the most part, running PHP either way does not matter.  However, if you're running PHP as a CGI, you need to be more careful about sending necessary headers.

It looks to me like your script attempts to fetch the addresses, doesn't find any, and outputs an error.  If PHP is running as a CGI, if the error output does not also output HTTP headers, you can get that error.

Want the best answers? Ask the best questions!

TANSTAAFL!!

RE: Bad header=No recipient addresses found

(OP)
The script definitely finds e-mail addresses and sends e-mails to them - it just doesn't send e-mails to everyone. It's a very hard thing to test without spamming the users with e-mail messages say "Just testing - ignore"

What would be the best way for me to work out how PHP is running on my server? I've got SSH access.

Cheers
Tama

I do my sums on fingers and thumbs.

RE: Bad header=No recipient addresses found

I would examine httpd.conf.  Is Apache loading mod_php?

Want the best answers? Ask the best questions!

TANSTAAFL!!

RE: Bad header=No recipient addresses found

(OP)
OK - found it out:

PHP runs in CGI-BIN mode on my new server, and ran in Apache module mode on my old server.

I do my sums on fingers and thumbs.

RE: Bad header=No recipient addresses found

That's related to your problem.  If you're running PHP as a web-server module, you don't have to worry about the "Content-Type:" and other HTTP headers.  If you're running PHP as a CGI, however, you do.  At least on Unix-like OSes -- I believe the Win32 version automatically outputs headers when run.

The problem is that somewhere in your code, you're outputting the error message "No recipient addresses found", but are not also outputting at least a "Content-Type:" header.

Want the best answers? Ask the best questions!

TANSTAAFL!!

RE: Bad header=No recipient addresses found

(OP)
A gotcha - so in my send function I need to send a Content-Type Header

I do my sums on fingers and thumbs.

RE: Bad header=No recipient addresses found

You need to set the header whereever it is you're sending that error message.

Or just send the header at the beginning of the script.

Want the best answers? Ask the best questions!

TANSTAAFL!!

RE: Bad header=No recipient addresses found

(OP)
This is in the script -

CODE

echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";

But do I need to make this into a Header command like this one:

CODE

header("Cache-Control: no-store, no-cache, must-revalidate");

What's the correct syntax? Should I remove the HTML DOCTYPE?

I do my sums on fingers and thumbs.

RE: Bad header=No recipient addresses found

The doctype comment is different from the content-type.

I'd try just adding:

header('Location: text/html');

Want the best answers? Ask the best questions!

TANSTAAFL!!

RE: Bad header=No recipient addresses found

(OP)
Yikes! I put "header('Location: text/html');" in and got this error:

CODE

Not Found
The requested URL /text/html was not found on this server.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

--------------------------------------------------------------------------------
Apache/1.3.27 Server at www.vorb.org.nz Port 80

I do my sums on fingers and thumbs.

RE: Bad header=No recipient addresses found

Is all this taking place in an Apache ErrorDocument?

Want the best answers? Ask the best questions!

TANSTAAFL!!

RE: Bad header=No recipient addresses found

(OP)
Shouldn't I be using:

CODE

header('Content-type: text/html');

I do my sums on fingers and thumbs.

RE: Bad header=No recipient addresses found

[Bad words]

Yeah, Tama, you're right.  If I'd actually type what I mean, you'd be a lot better off.

Did:

header ("Content-type: text/html");

make a difference?

Want the best answers? Ask the best questions!

TANSTAAFL!!

RE: Bad header=No recipient addresses found

(OP)
Heh heh - I should have stopped and thought on that one too.

OK - put the content header thing in and it's still producing this page when I try and send e-mails:

CODE

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@mydomain.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

--------------------------------------------------------------------------------
Apache/1.3.27 Server at www.vorb.org.nz Port 80

I'm going to try and work out a way to test this without e-mailing my users all the time.

I do my sums on fingers and thumbs.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close