php: swiftmailer questions
i've开发者_如何学C just installed swiftmailer for php and i'm having some questions:
- there's issue with german umlauts - i'm getting wrong characters how do i need to encode the message body properly?
- is there a property in swiftmailer for getting the server log (the dialog when sending mail for debugging)
- how can i set the property if the mail is plain text or html?
thanks
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).'?=';
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.
精彩评论