PHPMailer ignores \ r \ n

I am currently having a problem with received emails that were sent from PHPMailer using plain / text messages. I am currently returning an email from the database, retrieving the string and storing $ message in the variable. A message in the database is formatted as such:

This is some email information. \r\n This is some more email information.

The received message shows the message with \ r \ n, and does not return a new line.

My PHPMailer code looks something like this:

$subject = $row['subject'];
$message = $row['message'];

// PHP Mailer
$mail = new PHPMailer();
$mail->From = "noreply@mywebsite.org";
$mail->FromName = "MyWebsite.org";
$mail->AddAddress('recipient@email.com');
$mail->ContentType = 'text/plain';
$mail->IsHTML(false);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $message;
if(!$email->Send()){
    echo "Mailer Error: " . $mail->ErrorInfo;
} 

My question is . How can I format the format correctly using PHPMailer? Is this a PHPMailer parameter, or am I doing something wrong in my code?

+3
source share
6

, \r\n - PHP . ""

+3

.

, \r\n , PHPMailer \r\n .

.

, $message = 'Line 1\r\nLine 2'; ( )

Line 1\r\nLine 2

while $message = "Line 1\r\nLine 2"; ( )

Line 1
Line 2

, AltBody HTML, .

+5

, , .

AltBody. .

$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

, $mail- > isHTML() true false. , . , , , AltBody , . HTML-, , , , , PHPMailer

+4

nl2br() ... phpmailer... ""; preg_replace - .

$string = nl2br ($ _ POST [ "message" ]);

php mailer ,

$mail- > Body = "$ string";

.. ... OK

+2
$body = stripcslashes(isset($body) 
? 
preg_replace('#(\\\r|\\\r\\\n|\\\n)#', '<br/>', $body) 
: 
false);
$body = str_replace("<br/><br/>","<br/>",$body);

!

+1

, . , , .

$body = nl2br($body);

0

All Articles