V
V
v3shin2019-01-10 23:23:43
PHP
v3shin, 2019-01-10 23:23:43

How to remove line breaks in email?

Hello. There was a problem with extra line breaks when receiving emails. The code is something like this:

function Send() {
  $header = '...';
  $body = $this->CreateBody();
  $result = $this->MailSend($header, $body);
  return $result;
}

function CreateBody() {
  $result = "";
  $result .= $this->EncodeString($this->Body, $this->Encoding);
  return $result;
}

function EncodeString ($str, $encoding = "base64") {
  $encoded = $this->FixEOL($str);
  if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  $encoded .= $this->LE;
  return $encoded;
}

function FixEOL($str) {
  $str = str_replace("\r\n", "\n", $str);
  $str = str_replace("\r", "\n", $str);
  $str = str_replace("\n", $this->LE, $str);
  return $str;
}

function MailSend($header, $body) {
  $to = '...';
  $sbj = '...';
  $rt = @mail($to, $sbj, $body, $header);
  return true;
}

As a result, $body is formed correctly just before sending, but in the letter it comes with extra hyphens that distort the text (screenshot from the properties of the letter in Yandex Mail). Tell me, please, in which direction to dig to correct the text?
5c38cd95e29c6486618386.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Dubrovin, 2019-01-11
@v3shin

Most likely the problem is here:

if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  $encoded .= $this->LE;

I really don’t see where your str gets into encoded, but if, for example, the line terminator is LF in str (which is more than likely), and your LE is CRLF, then the result will be LFCRLF. That's right - throw out any CR and LF terminators at the end of the line and add CRLF.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question