Closed Thread
Results 1 to 5 of 5

Thread: Problem with mail headers

  1. #1
    ReekenX's Avatar
    ReekenX is offline Programmer
    Join Date
    Jan 2007
    Location
    Lithuania
    Posts
    135
    Rep Power
    0

    Problem with mail headers

    Hi everyone. I have my own PHP framework. 3 months of hard work. I have done 7 websites with framework, but two days ago, I have found strange bug.

    I am using this function:

    Code:
    /**
     * Send mail
     *
     * @param  string $To          Send email to
     * @param  string $From        Send from
     * @param  string $Subject     Email subject
     * @param  string $Body        Email body
     * @param  string $Encoding    Encoding to use
     * @param  string $Type        Email type (html or plain)
     * @return void
     * @access public
     */
    if (!function_exists("send_mail"))
    {
        function 
    send_mail($To$From$Subject$Body$Encoding "iso-8859-1"$TYPE "plain")
        {
            
    $Headers  "From: " $From "\r\n";
            
    $Headers .= "Reply-To: " $From "\r\n";
            
    $Headers .= "Return-Path: " $From "\r\n";
            
    $Headers .= "Content-Type: text/" $TYPE "; charset=" $Encoding "\r\n";
            
    $Headers .= "X-mailer: ReekenX WForce Framework\r\n";
            
    mail($To$Subject$Body$Headers);       
        }

    The solution I have found is to replace \r\n with only \n. In 6 servers, my mail sending was correct, but in one, mail headers was seen in message body. Like:

    Code:
    From: sender@sender.com
    Reply-to: sender@sender.com
    (other headers seen here)
    
    Message text

    Can anybody explain why email sending with \r\n is bad, and with \n is right?

    Sorry for my poor english

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: Problem with mail headers

    \r is a carriage return (ASCII char 13), \n is a new line (ASCII char 10). Sometimes one or the other is required, sometimes both. It depends on the language used. I dunno why it isn't working ATM.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  4. #3
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: Problem with mail headers

    According to the RFC2822, all mail headers should be terminated with a CRLF (carriage return line-feed), so it is not an issue with your code. I could be wrong, but I have read some linux servers replace a LF with a CRLF automatically, thus creating a double CR which results CRCRLF [\r\r\n] and thus is invalid.

  5. #4
    TkTech's Avatar
    TkTech is offline The Crazy One
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    1,412
    Blog Entries
    1
    Rep Power
    31

    Re: Problem with mail headers

    PHP themselves recommend \r\n...however, they also state:

    Note: If messages are not received, try using a LF (\n) only. Some poor quality Unix mail transfer agents replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822

  6. #5
    ReekenX's Avatar
    ReekenX is offline Programmer
    Join Date
    Jan 2007
    Location
    Lithuania
    Posts
    135
    Rep Power
    0

    Re: Problem with mail headers

    Many thanks to everyone!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. function send() - problem with access mail
    By AdrianWierciochPHP in forum PHP Development
    Replies: 6
    Last Post: 01-21-2011, 11:42 AM
  2. sending mail - problem with access!
    By AdrianWierciochPHP in forum PHP Development
    Replies: 1
    Last Post: 01-18-2011, 11:11 AM
  3. Send Mail Problem
    By cakka in forum PHP Development
    Replies: 7
    Last Post: 11-08-2008, 04:15 PM
  4. mail problem
    By Tor in forum Linux Installation & Configuration
    Replies: 5
    Last Post: 03-24-2008, 04:35 AM
  5. Replies: 3
    Last Post: 08-16-2007, 04:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

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