Message.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. *
  12. * @package Swift
  13. * @subpackage Mime
  14. * @author Chris Corbyn
  15. */
  16. class Swift_Message extends Swift_Mime_SimpleMessage
  17. {
  18. /**
  19. * Create a new Message.
  20. *
  21. * Details may be optionally passed into the constructor.
  22. *
  23. * @param string $subject
  24. * @param string $body
  25. * @param string $contentType
  26. * @param string $charset
  27. */
  28. public function __construct($subject = null, $body = null, $contentType = null, $charset = null)
  29. {
  30. call_user_func_array(
  31. array($this, 'Swift_Mime_SimpleMessage::__construct'),
  32. Swift_DependencyContainer::getInstance()
  33. ->createDependenciesFor('mime.message')
  34. );
  35. if (!isset($charset)) {
  36. $charset = Swift_DependencyContainer::getInstance()
  37. ->lookup('properties.charset');
  38. }
  39. $this->setSubject($subject);
  40. $this->setBody($body);
  41. $this->setCharset($charset);
  42. if ($contentType) {
  43. $this->setContentType($contentType);
  44. }
  45. }
  46. /**
  47. * Create a new Message.
  48. *
  49. * @param string $subject
  50. * @param string $body
  51. * @param string $contentType
  52. * @param string $charset
  53. *
  54. * @return Swift_Mime_Message
  55. */
  56. public static function newInstance($subject = null, $body = null, $contentType = null, $charset = null)
  57. {
  58. return new self($subject, $body, $contentType, $charset);
  59. }
  60. /**
  61. * Add a MimePart to this Message.
  62. *
  63. * @param string|Swift_OutputByteStream $body
  64. * @param string $contentType
  65. * @param string $charset
  66. *
  67. * @return Swift_Mime_SimpleMessage
  68. */
  69. public function addPart($body, $contentType = null, $charset = null)
  70. {
  71. return $this->attach(Swift_MimePart::newInstance(
  72. $body, $contentType, $charset
  73. ));
  74. }
  75. public function __wakeup()
  76. {
  77. Swift_DependencyContainer::getInstance()->createDependenciesFor('mime.message');
  78. }
  79. }