我使用 Laminas(以前的 Zendframework 3)。我想用 Laminas-Mail 發(fā)送郵件。我不知道如何更改Content-Type。目前是,Content-Type: text/html但我想發(fā)送 UTF8 郵件,因此我想使用Content-Type: text/html; charset=utf-8.我嘗試改變$html->type,但失敗了。use Laminas\Mail;use Laminas\Mail\Transport\Smtp as SmtpTransport;use Laminas\Mail\Transport\SmtpOptions;use Laminas\Mime\Message as MimeMessage;use Laminas\Mime\Part as MimePart;# ...# much code# ...// Produce HTML$bodyHtml = $this->viewRenderer->render('mymodule/email/email1');$html = new MimePart($bodyHtml);$html->type = "text/html; charset=utf-8"; #Seems not to work$body = new MimeMessage();$body->addPart($html);$mail = new Mail\Message();$mail->setEncoding('UTF-8');$mail->setBody($body);$mail->setFrom('bobafit@example.com','Boba Fit');$mail->addTo('bobafit@example.com','Boba Fit');$mail->setSubject('Thank you for reading my Question');// Setup SMTP transport$transport = new SmtpTransport();$options = new SmtpOptions($this->config['smtp']);$transport->setOptions($options);$transport->send($mail);
1 回答

天涯盡頭無女友
TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個(gè)贊
類型和字符集是分開定義的。
您可能正在尋找類似的東西:
$html = new MimePart($htmlMarkup);
$html->type = Mime::TYPE_HTML;
$html->charset = 'utf-8';
- 1 回答
- 0 關(guān)注
- 243 瀏覽
添加回答
舉報(bào)
0/150
提交
取消