MessageInterface.php 6.42 KB
Newer Older
1 2 3 4 5 6 7
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

Paul Klimov committed
8
namespace yii\mail;
9 10

/**
11
 * MessageInterface is an interface, which email message should apply.
12 13 14
 * Together with application component, which matches the [[MailerInterface]],
 * it introduces following mail sending syntax:
 * ~~~php
15 16 17 18
 * Yii::$app->mail->compose()
 *     ->from('from@domain.com')
 *     ->to('to@domain.com')
 *     ->subject('Message Subject')
19 20 21 22 23 24
 *     ->renderText('text/view')
 *     ->renderHtml('html/view')
 *     ->send();
 * ~~~
 *
 * @see MailerInterface
25 26 27 28 29 30
 *
 * @author Paul Klimov <klimov.paul@gmail.com>
 * @since 2.0
 */
interface MessageInterface
{
31 32 33
	/**
	 * Set the character set of this message.
	 * @param string $charset character set name.
34
	 * @return static self reference.
35 36 37
	 */
	public function setCharset($charset);

38 39 40 41 42 43
	/**
	 * Sets message sender.
	 * @param string|array $from sender email address.
	 * You may pass an array of addresses if this message is from multiple people.
	 * You may also specify sender name in addition to email address using format:
	 * [email => name].
44
	 * @return static self reference.
45
	 */
46
	public function from($from);
47 48 49 50 51 52 53

	/**
	 * Sets message receiver.
	 * @param string|array $to receiver email address.
	 * You may pass an array of addresses if multiple recipients should receive this message.
	 * You may also specify receiver name in addition to email address using format:
	 * [email => name].
54
	 * @return static self reference.
55
	 */
56
	public function to($to);
57 58 59 60 61 62 63

	/**
	 * Set the Cc (additional copy receiver) addresses of this message.
	 * @param string|array $cc copy receiver email address.
	 * You may pass an array of addresses if multiple recipients should receive this message.
	 * You may also specify receiver name in addition to email address using format:
	 * [email => name].
64
	 * @return static self reference.
65
	 */
66
	public function cc($cc);
67 68 69 70 71 72 73

	/**
	 * Set the Bcc (hidden copy receiver) addresses of this message.
	 * @param string|array $bcc hidden copy receiver email address.
	 * You may pass an array of addresses if multiple recipients should receive this message.
	 * You may also specify receiver name in addition to email address using format:
	 * [email => name].
74
	 * @return static self reference.
75
	 */
76
	public function bcc($bcc);
77 78 79 80

	/**
	 * Sets message subject.
	 * @param string $subject message subject
81
	 * @return static self reference.
82
	 */
83
	public function subject($subject);
84 85 86 87

	/**
	 * Sets message plain text content.
	 * @param string $text message plain text content.
88
	 * @return static self reference.
89
	 */
90
	public function text($text);
91 92 93 94

	/**
	 * Sets message HTML content.
	 * @param string $html message HTML content.
95
	 * @return static self reference.
96
	 */
97
	public function html($html);
98 99

	/**
100
	 * Attach specified content as file for the email message.
101
	 * @param string $content attachment file content.
102 103 104
	 * @param array $options options for embed file. Valid options are:
	 * - fileName: name, which should be used to attach file.
	 * - contentType: attached file MIME type.
105
	 * @return static self reference.
106
	 */
107
	public function attachContent($content, array $options = []);
108 109 110 111

	/**
	 * Attaches existing file to the email message.
	 * @param string $fileName full file name
112 113 114
	 * @param array $options options for embed file. Valid options are:
	 * - fileName: name, which should be used to attach file.
	 * - contentType: attached file MIME type.
115
	 * @return static self reference.
116
	 */
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
	public function attachFile($fileName, array $options = []);

	/**
	 * Attach a file and return it's CID source.
	 * This method should be used when embedding images or other data in a message.
	 * @param string $fileName file name.
	 * @param array $options options for embed file. Valid options are:
	 * - fileName: name, which should be used to attach file.
	 * - contentType: attached file MIME type.
	 * @return string attachment CID.
	 */
	public function embedFile($fileName, array $options = []);

	/**
	 * Attach a content as file and return it's CID source.
	 * This method should be used when embedding images or other data in a message.
	 * @param string $content  attachment file content.
	 * @param array $options options for embed file. Valid options are:
	 * - fileName: name, which should be used to attach file.
	 * - contentType: attached file MIME type.
	 * @return string attachment CID.
	 */
	public function embedContent($content, array $options = []);
140 141 142 143 144 145 146 147

	/**
	 * Sends this email message.
	 * @return boolean success.
	 */
	public function send();

	/**
148
	 * Fills up HTML body rendering a view.
149
	 * The view to be rendered can be specified in one of the following formats:
150 151
	 * - path alias (e.g. "@app/mails/contact/body");
	 * - relative path (e.g. "contact"): the actual view file will be resolved by [[\yii\base\ViewContextInterface]].
152 153
	 * @param string $view the view name or the path alias of the view file.
	 * @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
154
	 * @return static self reference.
155
	 */
156 157 158 159 160 161 162 163 164 165 166 167
	public function renderHtml($view, $params = []);

	/**
	 * Fills up plain text body rendering a view.
	 * The view to be rendered can be specified in one of the following formats:
	 * - path alias (e.g. "@app/mails/contact/body");
	 * - relative path (e.g. "contact"): the actual view file will be resolved by [[\yii\base\ViewContextInterface]].
	 * @param string $view the view name or the path alias of the view file.
	 * @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
	 * @return static self reference.
	 */
	public function renderText($view, $params = []);
168

169 170 171 172 173 174 175 176 177 178 179
	/**
	 * Composes the message HTML and plain text body.
	 * @param string|array $view varies method behavior depending on type:
	 *  - string - the view name or the path alias of the HTML body view file, in this case
	 * text body will be composed from html one using [[strip_tags()]] function.
	 *  - array - list of views for each body type in format: ['html' => 'htmlView', 'text' => 'textView']
	 * @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
	 * @return static self reference.
	 */
	public function body($view, $params = []);

180 181 182 183 184 185
	/**
	 * String output.
	 * This is PHP magic method that returns string representation of an object.
	 * @return string the string representation of the object
	 */
	public function __toString();
186
}