Message.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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,
  26. $contentType = null, $charset = null)
  27. {
  28. call_user_func_array(
  29. array($this, 'Swift_Mime_SimpleMessage::__construct'),
  30. Swift_DependencyContainer::getInstance()
  31. ->createDependenciesFor('mime.message')
  32. );
  33. if (!isset($charset))
  34. {
  35. $charset = Swift_DependencyContainer::getInstance()
  36. ->lookup('properties.charset');
  37. }
  38. $this->setSubject($subject);
  39. $this->setBody($body);
  40. $this->setCharset($charset);
  41. if ($contentType)
  42. {
  43. $this->setContentType($contentType);
  44. }
  45. }
  46. /**
  47. * Create a new Message.
  48. * @param string $subject
  49. * @param string $body
  50. * @param string $contentType
  51. * @param string $charset
  52. * @return Swift_Mime_Message
  53. */
  54. public static function newInstance($subject = null, $body = null,
  55. $contentType = null, $charset = null)
  56. {
  57. return new self($subject, $body, $contentType, $charset);
  58. }
  59. /**
  60. * Add a MimePart to this Message.
  61. * @param string|Swift_OutputByteStream $body
  62. * @param string $contentType
  63. * @param string $charset
  64. */
  65. public function addPart($body, $contentType = null, $charset = null)
  66. {
  67. return $this->attach(Swift_MimePart::newInstance(
  68. $body, $contentType, $charset
  69. ));
  70. }
  71. public function __wakeup()
  72. {
  73. Swift_DependencyContainer::getInstance()->createDependenciesFor('mime.message');
  74. }
  75. }