Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-11-2006, 01:50 AM   PM User | #1
MrZystem
New to the CF scene

 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
MrZystem is an unknown quantity at this point
Insane mail() problem causes 500 error

I have the following two tiny scripts running on an Apache/PHP server at a hosting provider.

Script 1:
PHP Code:
<?php

echo " ";
mail("non_existent_address@mydomain.com""test email!""This is a test.""From: me@mydomain.com");

?>
Script 2:
PHP Code:
<?php

mail
("non_existent_address@mydomain.com""test email!""This is a test.""From: me@mydomain.com");

?>
- Note that we are sending email to a non-existent email address. If we use existing addresses, the problem does not occur.
- Note that the only difference between the scripts is the removal of the echo in script 2.

Script 1 nicely returns a message saying a dead.letter was made which is lovely. Script 2 however, generates an internal server error 500. The server log will claim "malformed header from script".

Why does this happen and how to prevent the 500 error?
Thanks for any advice at all!

(Please help, as I run a forum, and when users have an email subscription to a certain thread, a bunch of mail() will be sent when someone replies in the thread. Some users may no longer have a valid email address, and the poster will get a nice Internal server 500 error rather than a normal error message when they innocently try to post a reply somewhere.
MrZystem is offline   Reply With Quote
Old 07-11-2006, 10:44 AM   PM User | #2
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Try adding '\r\n' to the end of your From: header, like so:

PHP Code:
<?php

mail
("non_existent_address@mydomain.com""test email!""This is a test.""From: me@mydomain.com\r\n");

?>
'\r\n' should ALWAYS appear after every mail header line...

See if that helps...Also, is that the only code in the entire file?

Quote:
Edit: you also might want to consider doing a check to see if an email's hostname is valid (before sending your emails)....use gethostbyname()
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)

Last edited by chump2877; 07-11-2006 at 10:48 AM..
chump2877 is offline   Reply With Quote
Old 07-11-2006, 10:58 AM   PM User | #3
MrZystem
New to the CF scene

 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
MrZystem is an unknown quantity at this point
Adding \n or indeed \r\n does not help.

Yes this is the only code in the entire file. It used to be a large script (part of a Joomla component) but weird 500 errors caused me to strip more and more code.

I also contacted the hosting provider about this, but no answer as yet.
MrZystem is offline   Reply With Quote
Old 07-11-2006, 11:30 AM   PM User | #4
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
The only other thing I can think of is to use single quotes instead of double quotes, so special characters aren;t interpreted:

PHP Code:
<?php

mail
('non_existent_address@mydomain.com''test email!''This is a test.''From: me@mydomain.com'."\r\n");

?>
If it's not that, it's likely something in your PHP or Apache configuration....Also, can you cut and paste the exact error message in this post...
__________________
Regards, R.J.

---------------------------------------------------------

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)

Last edited by chump2877; 07-11-2006 at 11:35 AM..
chump2877 is offline   Reply With Quote
Old 07-11-2006, 09:52 PM   PM User | #5
MrZystem
New to the CF scene

 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
MrZystem is an unknown quantity at this point
Changing the quotes does not help unfortunately.

The error is a standard 500 internal server error, but the serverlog says:

[Tue Jul 11 14:14:19 2006] [error] [client x.x.x.x] malformed header from script. Bad header=dead.letter... Sa: php-script

However, the hosting provider has answered: they don't know the cause of the problem but the solution is to put the following parameter in the mail() command:

"-fme@mydomain.com"

The script will look like this:

PHP Code:
<?php

mail
('non_existent_address@mydomain.com''test email!''This is a test.''From: me@mydomain.com'."\r\n",  "-fme@mydomain.com");

?>
The mail() no longer displays any output, but the Internal Server Error 500 is gone. Hope this helps, I found this problem on many forums but none had a solution.
MrZystem is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:58 AM.


Advertisement
Log in to turn off these ads.