Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,791
    Thanks
    19
    Thanked 156 Times in 147 Posts
    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?

    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()
    Last edited by chump2877; 07-11-2006 at 10:48 AM.
    Regards, R.J.

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

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,791
    Thanks
    19
    Thanked 156 Times in 147 Posts
    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...
    Last edited by chump2877; 07-11-2006 at 11:35 AM.
    Regards, R.J.

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

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #5
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •