Page 1 of 1

Email Script Windows vs Linux

Posted: Thu Oct 28, 2004 3:36 pm
by arach2k5
Hi all -

Trying to get an email form script working in a Linux environment. The script works just fine in a Windows environment (collects data from form, attaches message and emails it), but when run in a Linux environment, the email looks weird.

Basically when you receive the email, it has all the MIME codes exposed and visible in the body of the email, and worse, the attachment seems to get sent as text - you can see all the hex codes that make up the files as text at the end of the email.

My question is: is there some change I need to make to the code when running on a Linux server vs a Windows server? Any help very much appreciated - thanks!

A

Posted: Thu Oct 28, 2004 3:48 pm
by mudkicker
any code to show us?

Posted: Thu Oct 28, 2004 5:30 pm
by rehfeld
sometimes weird things happen if you use \r\n to terminate line endings in the headers on *nix, but you MUST use \r\n on win

i use this to get around it, maybe it will solve your problem

Code: Select all

function send_email($from, $to, $subject, $message)
{
    $headers  = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/plain; charset=iso-8859-1\n";
    $headers .= "X-Priority: 1\n";
    $headers .= "X-MSMail-Priority: High\n";
    $headers .= "X-Mailer: php\n";
    $headers .= "From: <$from>\n";
    $headers .= "Reply-To: <$from>\n";

    if (false !== strpos(PHP_OS, 'WIN')) {
        $headers = str_replace("\n", "\r\n", $headers);
    }

    return (mail($to, $subject, $message, $headers));
}

Posted: Thu Oct 28, 2004 5:37 pm
by rehfeld
also, i "think" i read somewhere that having a lone linefeed ("\n") in the message body was against rfc or was just a no-no on many systems, and that it must be "\r\n"

might look into that too.