层压邮件。作为 UFT8 发送
Laminas-mail. send as UFT8
我使用 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);
请查看官方Dok:
https://docs.laminas.dev/laminas-mail/message/attachments/
类型和字符集是分开定义的。
您可能正在寻找类似的东西:
$html = new MimePart($htmlMarkup);
$html->type = Mime::TYPE_HTML;
$html->charset = 'utf-8';
我使用 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);
请查看官方Dok:
https://docs.laminas.dev/laminas-mail/message/attachments/
类型和字符集是分开定义的。
您可能正在寻找类似的东西:
$html = new MimePart($htmlMarkup);
$html->type = Mime::TYPE_HTML;
$html->charset = 'utf-8';