【问题标题】:Headers and MIME types for HTML email messages (sending through PHP)HTML 电子邮件的标题和 MIME 类型(通过 PHP 发送)
【发布时间】:2010-02-23 18:00:04
【问题描述】:

对于仅包含 HTML 内容而非混合类型(包含文本和 HTML)的电子邮件,正确的标题信息和 MIME 类型是什么。

只是通知一下,我正在使用 Swiftmailer (PHP) 来完成这项工作。

【问题讨论】:

    标签: html email header mime-types


    【解决方案1】:

    这是我的代码:

    $swift = new stdClass();
    $swift->transport = Swift_SendmailTransport::newInstance( '/usr/sbin/sendmail -bs' );
    $swift->mailer = Swift_Mailer::newInstance( $swift->transport );
    $swift->message = Swift_Message::newInstance('Title')
        ->setFrom( array('from@my.email' => 'Me') )
        ->setTo( array( 'to@some.one' => 'Some One' ) )
        ->setBody('<h1>It works!</h1>', 'text/html');
    

    您还可以查看 http://swiftmailer.org/docs/headers 上的 Headers 文档

    【讨论】:

    • 我已经这样做了,但是它两次添加了消息的内容。我尝试在没有'text/html'的情况下插入html代码并在之后插入mime标题: $headers = $message->getHeaders(); if ($headers->has('MIME-Version')) { $MIME_Version = $headers->get('MIME-Version'); $MIME_Version->setValue('1.0'); } else { $headers->addTextHeader('MIME-Version', '1.0'); } if ($headers->has('Content-type')) { $Content_type = $headers->get('Content-type'); $Content_type->setValue('text/html'); } else { $headers->addTextHeader('Content-type', 'text/html');但令人难以置信的是,同样的错误一直在发生
    • 这是正确的(在编程方面),但仍然出现错误
    猜你喜欢
    • 1970-01-01
    • 2013-08-29
    • 2016-07-16
    • 2012-04-01
    • 2012-06-29
    • 1970-01-01
    • 1970-01-01
    • 2022-10-23
    相关资源
    最近更新 更多