PHPMailer plain text email adds new line at the end

时间:2016-04-07 10:30:00

标签: php email phpmailer plaintext

I'm trying to get rid of new line at the end of plain text email message I'm sending with PHPMailer.

What I'm doing exactly is:

$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->isHTML(false);  
$mail->Body = $xxx1."\r\n".$xxx2."\r\n".$xxx3;
$mail->setFrom("no-reply@xxx.xx", "xxx");
$mail->addReplyTo("no-reply@xxx.xx", "xxx");
$mail->addAddress($to, $name);
$mail->Subject = $topic;
$mail->send();  

Everything is fine except for the new line that is being added after the message body, it's something like:

msg screenshot

Maybe someone has any idea how to remove that newline marker from the end of message?

Thanks!

EDIT: $xxx3 variable is a param passed to mail sending function. It is set to either "no" or "yes".

1 个答案:

答案 0 :(得分:1)

PHPMailer does add line breaks while it's assembling the MIME structure for a message. See the createBody method. I think there is an RFC requirement that message bodies must end with a line break (can't remember exactly which one right now), so one is always added to make sure. If it's that critical I'd recommend you strip your trailing line break first:

$mail->Body = rtrim($xxx1."\r\n".$xxx2."\r\n".$xxx3, "\r\n");