PHP - there is a stray CR character in the message

I'm sending out email and a certain email keeps keeping bounced back.  This is the error:
      Remote host said: 501 5.5.2 there is a stray CR character in the message

I've fixed this in the past by using \n instead of \r\n (something like that) but now getting this message from an email.  Can someone tell me how I go about finding a CR character in a message.  Below is the function I use to send mail, it's part of a custom mail class.

    function send() {
      ini_set('sendmail_from', $this->fromName.' <'.$this->from.'>');
           
      $headers  = "{$this->mime}\n";
      $headers .= "{$this->currContentType}\n";
      $headers .= "From: {$this->fromName} <{$this->from}>\n";
      $headers .= "Reply-To: {$this->replyToName} <{$this->replyTo}>\n";
           
      if ($this->bcc != NULL) {
        $headers .= "Bcc: {$this->bccName} <{$this->bcc}>\n";              
      }

      mail($this->toName.' <'.$this->to.'>', $this->subject, $this->message, $headers);
  }
ronpacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hernst42Commented:
you will need \r\n instead of only \n

http://de3.php.net/manual/en/function.mail.php
Note:  You must use \r\n to separate headers, although some Unix mail transfer agents may work with just a single newline (\n).

e.g
 $headers  = "{$this->mime}\r\n";
      $headers .= "{$this->currContentType}\r\n";
      $headers .= "From: {$this->fromName} <{$this->from}>\r\n";
      $headers .= "Reply-To: {$this->replyToName} <{$this->replyTo}>\r\n";
..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gripeCommented:
Try printing your $headers variable to the screen. You should see the stray character as a line break. It's likely in one of your variables.
0
ronpacAuthor Commented:
gripe, I printed the headers, here they are:
Content-type: text/html; charset=iso-8859-1
From: BnBFinder.com <email@email.com>
Reply-To: BnBFinder.com <email@email.com>
Bcc:  <email@email.com>


There was no line feed after bcc.  I actually get the message as a bcc but the person I'm sending it gets bounced back so I assume it's the receiving server and not mine that is the problem.

hernst42, I tried adding the \r\n and it did not work, thanks though.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

ronpacAuthor Commented:
please not that email@email.com is not the real address, just changed it for this posting...not that it matters because I didn't change the name ~sigh~
0
hernst42Commented:
Might be a problem if no bcc is given so this might work:

      $headers .= "Reply-To: {$this->replyToName} <{$this->replyTo}>";
           
      if ($this->bcc != NULL) {
        $headers .= "\r\nBcc: {$this->bccName} <{$this->bcc}>";            
      }

But I guess you tried that already?
0
ronpacAuthor Commented:
The bcc is always given in this case. I actually get the bcc but the client doesn't get the message....I tried taking off the \n from the bcc but that didn't work either, I try that again though.
0
Marcus BointonCommented:
Try using phpmailer - it deals with line breaks properly for you, and it's much easier and more reliable than using mail().

http://phpmailer.sourceforge.net/
0
ronpacAuthor Commented:
never found a solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.