Fuxi
Fuxi

Reputation: 7599

php: swiftmailer questions

i've just installed swiftmailer for php and i'm having some questions:

  1. there's issue with german umlauts - i'm getting wrong characters how do i need to encode the message body properly?
  2. is there a property in swiftmailer for getting the server log (the dialog when sending mail for debugging)
  3. how can i set the property if the mail is plain text or html?

thanks

Upvotes: 2

Views: 4192

Answers (2)

nanobar
nanobar

Reputation: 66355

set plain text or html like this

$message = Swift_Message::newInstance($subject)
->setFrom(...)
->setTo(....)
->setBody($message, 'text/html')
;

for plain text change to setBody($message, 'text/plain')

Alternatively set it with:

$message->setContentType('text/html')

or

$message->setContentType('text/plain')

To get umlauts working try this:

$message->setContentType('text/plain; charset=UTF-8')

change plain to html for html emails obviously

You can also set it globally with:

Swift_Preferences::getInstance()->setCharset('UTF-8');

However this is default so it is strange you are having problems. Is the problem with the message body or subject? If it is with the subject try:

$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';

Upvotes: 7

Charles
Charles

Reputation: 51411

there's issue with german umlauts - i'm getting wrong characters how do i need to encode the message body properly?

You can set the character set using the third parameter of setBody or addPart. You'll want to make sure that the passed string is already in that character set.

is there a property in swiftmailer for getting the server log (the dialog when sending mail for debugging)

You should be able to do this by enabling one of the logging plugins.

how can i set the property if the mail is plain text or html?

You can define the HTML-yness of a message by passing the content type to setBody or addPart.

I highly recommend that you browse through the comprehensive online documentation for more information on these topics.

Upvotes: 4

Related Questions