eGz3
eGz3

Reputation: 15

PHPMailer plain text email adds new line at the end

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("[email protected]", "xxx");
$mail->addReplyTo("[email protected]", "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".

Upvotes: 0

Views: 1585

Answers (1)

Synchro
Synchro

Reputation: 37730

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");

Upvotes: 1

Related Questions