Email Script Windows vs Linux

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arach2k5
Forum Newbie
Posts: 2
Joined: Mon Oct 25, 2004 5:17 pm

Email Script Windows vs Linux

Post 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
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

any code to show us?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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));
}
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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.
Post Reply