Gajus
Gajus

Reputation: 73888

swiftmailer text/plain line breaks?

I am trying to send a message using PHPs mail library called Swiftmailer. The problem is that the text is rendered without line breaks and I can't really see the reason for that. I've tried reading the mail using gmail and yahoo.

The code:

// [..] bla bla
$message->setBody("a\r\nb", 'text/plain')

Upvotes: 4

Views: 3647

Answers (2)

Mark Santos
Mark Santos

Reputation: 377

You can use PHP_EOL Example:

    ->setBody('Hi Sir/Mam,'.PHP_EOL.'Here is my message.')

Upvotes: 2

Marc B
Marc B

Reputation: 360752

HTML doesn't obey line breaks (they're treated as spaces). You need to use <br /> tags instead. If you're filling in plaintext dynamically, you can use PHP's nl2br() to do this for you.

Upvotes: 1

Related Questions