Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 555
  • Last Modified:

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);
  }
0
ronpac
Asked:
ronpac
2 Solutions
 
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
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now