Message.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. * (c) 2004-2009 Chris Corbyn
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * The Message class for building emails.
  11. * @package Swift
  12. * @subpackage Mime
  13. * @author Chris Corbyn
  14. */
  15. class Swift_Message extends Swift_Mime_SimpleMessage
  16. {
  17. /**
  18. * Create a new Message.
  19. * Details may be optionally passed into the constructor.
  20. * @param string $subject
  21. * @param string $body
  22. * @param string $contentType
  23. * @param string $charset
  24. */
  25. public function __construct($subject = null, $body = null, $contentType = null, $charset = null)
  26. {
  27. call_user_func_array(
  28. array($this, 'Swift_Mime_SimpleMessage::__construct'),
  29. Swift_DependencyContainer::getInstance()
  30. ->createDependenciesFor('mime.message')
  31. );
  32. if (!isset($charset)) {
  33. $charset = Swift_DependencyContainer::getInstance()
  34. ->lookup('properties.charset');
  35. }
  36. $this->setSubject($subject);
  37. $this->setBody($body);
  38. $this->setCharset($charset);
  39. if ($contentType) {
  40. $this->setContentType($contentType);
  41. }
  42. }
  43. /**
  44. * Create a new Message.
  45. * @param string $subject
  46. * @param string $body
  47. * @param string $contentType
  48. * @param string $charset
  49. * @return Swift_Mime_Message
  50. */
  51. public static function newInstance($subject = null, $body = null, $contentType = null, $charset = null)
  52. {
  53. return new self($subject, $body, $contentType, $charset);
  54. }
  55. /**
  56. * Add a MimePart to this Message.
  57. * @param string|Swift_OutputByteStream $body
  58. * @param string $contentType
  59. * @param string $charset
  60. */
  61. public function addPart($body, $contentType = null, $charset = null)
  62. {
  63. return $this->attach(Swift_MimePart::newInstance(
  64. $body, $contentType, $charset
  65. ));
  66. }
  67. public function __wakeup()
  68. {
  69. Swift_DependencyContainer::getInstance()->createDependenciesFor('mime.message');
  70. }
  71. }