我使用 Laminas(以前的 Zendframework 3)。我想用 Laminas-Mail 发送邮件。我不知道如何更改Content-Type。目前是,Content-Type: text/html但我想发送 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贡献1831条经验 获得超9个赞
类型和字符集是分开定义的。
您可能正在寻找类似的东西:
$html = new MimePart($htmlMarkup);
$html->type = Mime::TYPE_HTML;
$html->charset = 'utf-8';
- 1 回答
- 0 关注
- 206 浏览
添加回答
举报
0/150
提交
取消