【问题标题】:Send HTML mail with fallback to plain text mail via Swiftmailer通过 Swiftmailer 发送带有回退到纯文本邮件的 HTML 邮件
【发布时间】:2015-03-30 19:55:02
【问题描述】:

如何使用 PHP Swiftmailer 发送 HTML 邮件并退回到纯文本邮件?

【问题讨论】:

    标签: php email swiftmailer


    【解决方案1】:

    在 Swiftmailer 中创建消息并使用setBody() 函数设置邮件的文本/纯文本版本并使用addPart() 函数设置电子邮件的文本/html 版本(带有第二个参数text/html) :

    $message = Swift_Message::newInstance()
      ->setSubject('Your subject')
      ->setFrom(array('john@doe.com' => 'John Doe'))
      ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
      ->setBody('Here is the message itself')
      ->addPart('<p>Here is the message itself</p>', 'text/html')
      ;
    

    查看来源:http://swiftmailer.org/docs/messages.html

    【讨论】:

      猜你喜欢
      • 2016-03-13
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 2011-08-27
      相关资源
      最近更新 更多