Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ########### |
| 2 | Email Class |
| 3 | ########### |
| 4 | |
| 5 | CodeIgniter's robust Email Class supports the following features: |
| 6 | |
| 7 | - Multiple Protocols: Mail, Sendmail, and SMTP |
| 8 | - TLS and SSL Encryption for SMTP |
| 9 | - Multiple recipients |
| 10 | - CC and BCCs |
| 11 | - HTML or Plaintext email |
| 12 | - Attachments |
| 13 | - Word wrapping |
| 14 | - Priorities |
| 15 | - BCC Batch Mode, enabling large email lists to be broken into small |
| 16 | BCC batches. |
| 17 | - Email Debugging tools |
| 18 | |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 19 | .. contents:: |
| 20 | :local: |
| 21 | |
| 22 | .. raw:: html |
| 23 | |
| 24 | <div class="custom-index container"></div> |
| 25 | |
| 26 | *********************** |
| 27 | Using the Email Library |
| 28 | *********************** |
| 29 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 30 | Sending Email |
| 31 | ============= |
| 32 | |
| 33 | Sending email is not only simple, but you can configure it on the fly or |
| 34 | set your preferences in a config file. |
| 35 | |
| 36 | Here is a basic example demonstrating how you might send email. Note: |
| 37 | This example assumes you are sending the email from one of your |
| 38 | :doc:`controllers <../general/controllers>`. |
| 39 | |
| 40 | :: |
| 41 | |
Derek Jones | 3c35684 | 2011-10-05 16:14:23 -0500 | [diff] [blame] | 42 | $this->load->library('email'); |
| 43 | |
| 44 | $this->email->from('your@example.com', 'Your Name'); |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 45 | $this->email->to('someone@example.com'); |
| 46 | $this->email->cc('another@another-example.com'); |
| 47 | $this->email->bcc('them@their-example.com'); |
Derek Jones | 3c35684 | 2011-10-05 16:14:23 -0500 | [diff] [blame] | 48 | |
| 49 | $this->email->subject('Email Test'); |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 50 | $this->email->message('Testing the email class.'); |
Derek Jones | 3c35684 | 2011-10-05 16:14:23 -0500 | [diff] [blame] | 51 | |
| 52 | $this->email->send(); |
| 53 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 54 | Setting Email Preferences |
| 55 | ========================= |
| 56 | |
Darren Benney | 7713081 | 2013-03-26 02:22:35 +0000 | [diff] [blame] | 57 | There are 21 different preferences available to tailor how your email |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 58 | messages are sent. You can either set them manually as described here, |
| 59 | or automatically via preferences stored in your config file, described |
| 60 | below: |
| 61 | |
| 62 | Preferences are set by passing an array of preference values to the |
Andrey Andreev | 5b60a3b | 2013-01-15 04:19:03 +0200 | [diff] [blame] | 63 | email initialize method. Here is an example of how you might set some |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 64 | preferences:: |
| 65 | |
Derek Jones | 3c35684 | 2011-10-05 16:14:23 -0500 | [diff] [blame] | 66 | $config['protocol'] = 'sendmail'; |
| 67 | $config['mailpath'] = '/usr/sbin/sendmail'; |
| 68 | $config['charset'] = 'iso-8859-1'; |
| 69 | $config['wordwrap'] = TRUE; |
| 70 | |
| 71 | $this->email->initialize($config); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 72 | |
| 73 | .. note:: Most of the preferences have default values that will be used |
| 74 | if you do not set them. |
| 75 | |
| 76 | Setting Email Preferences in a Config File |
| 77 | ------------------------------------------ |
| 78 | |
| 79 | If you prefer not to set preferences using the above method, you can |
| 80 | instead put them into a config file. Simply create a new file called the |
| 81 | email.php, add the $config array in that file. Then save the file at |
| 82 | config/email.php and it will be used automatically. You will NOT need to |
Andrey Andreev | 5b60a3b | 2013-01-15 04:19:03 +0200 | [diff] [blame] | 83 | use the ``$this->email->initialize()`` method if you save your |
| 84 | preferences in a config file. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 85 | |
| 86 | Email Preferences |
| 87 | ================= |
| 88 | |
| 89 | The following is a list of all the preferences that can be set when |
| 90 | sending email. |
| 91 | |
Joseph Wensley | d14717f | 2011-10-05 23:57:14 -0400 | [diff] [blame] | 92 | =================== ====================== ============================ ======================================================================= |
| 93 | Preference Default Value Options Description |
| 94 | =================== ====================== ============================ ======================================================================= |
| 95 | **useragent** CodeIgniter None The "user agent". |
| 96 | **protocol** mail mail, sendmail, or smtp The mail sending protocol. |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 97 | **mailpath** /usr/sbin/sendmail None The server path to Sendmail. |
Joseph Wensley | d14717f | 2011-10-05 23:57:14 -0400 | [diff] [blame] | 98 | **smtp_host** No Default None SMTP Server Address. |
| 99 | **smtp_user** No Default None SMTP Username. |
| 100 | **smtp_pass** No Default None SMTP Password. |
| 101 | **smtp_port** 25 None SMTP Port. |
| 102 | **smtp_timeout** 5 None SMTP Timeout (in seconds). |
nisheeth-barthwal | 9ecde43 | 2013-02-18 17:06:12 +0530 | [diff] [blame] | 103 | **smtp_keepalive** FALSE TRUE or FALSE (boolean) Enable persistent SMTP connections. |
Joseph Wensley | d14717f | 2011-10-05 23:57:14 -0400 | [diff] [blame] | 104 | **smtp_crypto** No Default tls or ssl SMTP Encryption |
| 105 | **wordwrap** TRUE TRUE or FALSE (boolean) Enable word-wrap. |
| 106 | **wrapchars** 76 Character count to wrap at. |
| 107 | **mailtype** text text or html Type of mail. If you send HTML email you must send it as a complete web |
| 108 | page. Make sure you don't have any relative links or relative image |
| 109 | paths otherwise they will not work. |
Andrey Andreev | 6d9915a | 2012-10-10 16:18:33 +0300 | [diff] [blame] | 110 | **charset** ``$config['charset']`` Character set (utf-8, iso-8859-1, etc.). |
Joseph Wensley | d14717f | 2011-10-05 23:57:14 -0400 | [diff] [blame] | 111 | **validate** FALSE TRUE or FALSE (boolean) Whether to validate the email address. |
| 112 | **priority** 3 1, 2, 3, 4, 5 Email Priority. 1 = highest. 5 = lowest. 3 = normal. |
| 113 | **crlf** \\n "\\r\\n" or "\\n" or "\\r" Newline character. (Use "\\r\\n" to comply with RFC 822). |
| 114 | **newline** \\n "\\r\\n" or "\\n" or "\\r" Newline character. (Use "\\r\\n" to comply with RFC 822). |
| 115 | **bcc_batch_mode** FALSE TRUE or FALSE (boolean) Enable BCC Batch Mode. |
| 116 | **bcc_batch_size** 200 None Number of emails in each BCC batch. |
leandronf | be07c92 | 2012-03-22 19:49:23 -0300 | [diff] [blame] | 117 | **dsn** FALSE TRUE or FALSE (boolean) Enable notify message from server |
Joseph Wensley | d14717f | 2011-10-05 23:57:14 -0400 | [diff] [blame] | 118 | =================== ====================== ============================ ======================================================================= |
| 119 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 120 | Overriding Word Wrapping |
| 121 | ======================== |
| 122 | |
| 123 | If you have word wrapping enabled (recommended to comply with RFC 822) |
| 124 | and you have a very long link in your email it can get wrapped too, |
| 125 | causing it to become un-clickable by the person receiving it. |
| 126 | CodeIgniter lets you manually override word wrapping within part of your |
| 127 | message like this:: |
| 128 | |
Derek Jones | 3c35684 | 2011-10-05 16:14:23 -0500 | [diff] [blame] | 129 | The text of your email that |
| 130 | gets wrapped normally. |
| 131 | |
| 132 | {unwrap}http://example.com/a_long_link_that_should_not_be_wrapped.html{/unwrap} |
| 133 | |
| 134 | More text that will be |
| 135 | wrapped normally. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 136 | |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 137 | |
| 138 | Place the item you do not want word-wrapped between: {unwrap} {/unwrap} |
| 139 | |
| 140 | *************** |
| 141 | Class Reference |
| 142 | *************** |
| 143 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 144 | .. php:class:: CI_Email |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 145 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 146 | .. php:method:: from($from[, $name = ''[, $return_path = NULL]]) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 147 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 148 | :param string $from: "From" e-mail address |
| 149 | :param string $name: "From" display name |
| 150 | :param string $return_path: Optional email address to redirect undelivered e-mail to |
| 151 | :returns: CI_Email instance (method chaining) |
| 152 | :rtype: CI_Email |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 153 | |
| 154 | Sets the email address and name of the person sending the email:: |
| 155 | |
| 156 | $this->email->from('you@example.com', 'Your Name'); |
| 157 | |
| 158 | You can also set a Return-Path, to help redirect undelivered mail:: |
| 159 | |
| 160 | $this->email->from('you@example.com', 'Your Name', 'returned_emails@example.com'); |
| 161 | |
| 162 | .. note:: Return-Path can't be used if you've configured 'smtp' as |
| 163 | your protocol. |
| 164 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 165 | .. php:method:: reply_to($replyto[, $name = '']) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 166 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 167 | :param string $replyto: E-mail address for replies |
| 168 | :param string $name: Display name for the reply-to e-mail address |
| 169 | :returns: CI_Email instance (method chaining) |
| 170 | :rtype: CI_Email |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 171 | |
| 172 | Sets the reply-to address. If the information is not provided the |
| 173 | information in the :meth:from method is used. Example:: |
| 174 | |
| 175 | $this->email->reply_to('you@example.com', 'Your Name'); |
| 176 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 177 | .. php:method:: to($to) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 178 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 179 | :param mixed $to: Comma-delimited string or an array of e-mail addresses |
| 180 | :returns: CI_Email instance (method chaining) |
| 181 | :rtype: CI_Email |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 182 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 183 | Sets the email address(s) of the recipient(s). Can be a single e-mail, |
| 184 | a comma-delimited list or an array:: |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 185 | |
| 186 | $this->email->to('someone@example.com'); |
| 187 | |
| 188 | :: |
| 189 | |
| 190 | $this->email->to('one@example.com, two@example.com, three@example.com'); |
| 191 | |
| 192 | :: |
| 193 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 194 | $this->email->to( |
| 195 | array('one@example.com', 'two@example.com', 'three@example.com') |
| 196 | ); |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 197 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 198 | .. php:method:: cc($cc) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 199 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 200 | :param mixed $cc: Comma-delimited string or an array of e-mail addresses |
| 201 | :returns: CI_Email instance (method chaining) |
| 202 | :rtype: CI_Email |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 203 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 204 | Sets the CC email address(s). Just like the "to", can be a single e-mail, |
| 205 | a comma-delimited list or an array. |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 206 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 207 | .. php:method:: bcc($bcc[, $limit = '']) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 208 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 209 | :param mixed $bcc: Comma-delimited string or an array of e-mail addresses |
| 210 | :param int $limit: Maximum number of e-mails to send per batch |
| 211 | :returns: CI_Email instance (method chaining) |
| 212 | :rtype: CI_Email |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 213 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 214 | Sets the BCC email address(s). Just like the ``to()`` method, can be a single |
| 215 | e-mail, a comma-delimited list or an array. |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 216 | |
| 217 | If ``$limit`` is set, "batch mode" will be enabled, which will send |
| 218 | the emails to batches, with each batch not exceeding the specified |
| 219 | ``$limit``. |
| 220 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 221 | .. php:method:: subject($subject) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 222 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 223 | :param string $subject: E-mail subject line |
| 224 | :returns: CI_Email instance (method chaining) |
| 225 | :rtype: CI_Email |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 226 | |
| 227 | Sets the email subject:: |
| 228 | |
| 229 | $this->email->subject('This is my subject'); |
| 230 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 231 | .. php:method:: message($body) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 232 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 233 | :param string $body: E-mail message body |
| 234 | :returns: CI_Email instance (method chaining) |
| 235 | :rtype: CI_Email |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 236 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 237 | Sets the e-mail message body:: |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 238 | |
| 239 | $this->email->message('This is my message'); |
| 240 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 241 | .. php:method:: set_alt_message($str) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 242 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 243 | :param string $str: Alternative e-mail message body |
| 244 | :returns: CI_Email instance (method chaining) |
| 245 | :rtype: CI_Email |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 246 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 247 | Sets the alternative e-mail message body:: |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 248 | |
| 249 | $this->email->set_alt_message('This is the alternative message'); |
| 250 | |
| 251 | This is an optional message string which can be used if you send |
| 252 | HTML formatted email. It lets you specify an alternative message |
| 253 | with no HTML formatting which is added to the header string for |
| 254 | people who do not accept HTML email. If you do not set your own |
| 255 | message CodeIgniter will extract the message from your HTML email |
| 256 | and strip the tags. |
| 257 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 258 | .. php:method:: set_header($header, $value) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 259 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 260 | :param string $header: Header name |
| 261 | :param string $value: Header value |
| 262 | :returns: CI_Email instance (method chaining) |
| 263 | :rtype: CI_Email |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 264 | |
| 265 | Appends additional headers to the e-mail:: |
| 266 | |
| 267 | $this->email->set_header('Header1', 'Value1'); |
| 268 | $this->email->set_header('Header2', 'Value2'); |
| 269 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 270 | .. php:method:: clear([$clear_attachments = FALSE]) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 271 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 272 | :param bool $clear_attachments: Whether or not to clear attachments |
| 273 | :returns: CI_Email instance (method chaining) |
| 274 | :rtype: CI_Email |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 275 | |
| 276 | Initializes all the email variables to an empty state. This method |
| 277 | is intended for use if you run the email sending method in a loop, |
| 278 | permitting the data to be reset between cycles. |
| 279 | |
| 280 | :: |
| 281 | |
| 282 | foreach ($list as $name => $address) |
| 283 | { |
| 284 | $this->email->clear(); |
| 285 | |
| 286 | $this->email->to($address); |
| 287 | $this->email->from('your@example.com'); |
| 288 | $this->email->subject('Here is your info '.$name); |
| 289 | $this->email->message('Hi '.$name.' Here is the info you requested.'); |
| 290 | $this->email->send(); |
| 291 | } |
| 292 | |
| 293 | If you set the parameter to TRUE any attachments will be cleared as |
| 294 | well:: |
| 295 | |
| 296 | $this->email->clear(TRUE); |
| 297 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 298 | .. php:method:: send([$auto_clear = TRUE]) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 299 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 300 | :param bool $auto_clear: Whether to clear message data automatically |
| 301 | :returns: TRUE on success, FALSE on failure |
| 302 | :rtype: bool |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 303 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 304 | The e-mail sending method. Returns boolean TRUE or FALSE based on |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 305 | success or failure, enabling it to be used conditionally:: |
| 306 | |
| 307 | if ( ! $this->email->send()) |
| 308 | { |
| 309 | // Generate error |
| 310 | } |
| 311 | |
| 312 | This method will automatically clear all parameters if the request was |
| 313 | successful. To stop this behaviour pass FALSE:: |
| 314 | |
| 315 | if ($this->email->send(FALSE)) |
| 316 | { |
| 317 | // Parameters won't be cleared |
| 318 | } |
| 319 | |
| 320 | .. note:: In order to use the ``print_debugger()`` method, you need |
| 321 | to avoid clearing the email parameters. |
| 322 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 323 | .. php:method:: attach($filename[, $disposition = ''[, $newname = NULL[, $mime = '']]]) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 324 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 325 | :param string $filename: File name |
| 326 | :param string $disposition: 'disposition' of the attachment. Most |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 327 | email clients make their own decision regardless of the MIME |
| 328 | specification used here. https://www.iana.org/assignments/cont-disp/cont-disp.xhtml |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 329 | :param string $newname: Custom file name to use in the e-mail |
| 330 | :param string $mime: MIME type to use (useful for buffered data) |
| 331 | :returns: CI_Email instance (method chaining) |
| 332 | :rtype: CI_Email |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 333 | |
| 334 | Enables you to send an attachment. Put the file path/name in the first |
Andrey Andreev | ea801ab | 2014-01-20 15:03:43 +0200 | [diff] [blame] | 335 | parameter. For multiple attachments use the method multiple times. |
| 336 | For example:: |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 337 | |
| 338 | $this->email->attach('/path/to/photo1.jpg'); |
| 339 | $this->email->attach('/path/to/photo2.jpg'); |
| 340 | $this->email->attach('/path/to/photo3.jpg'); |
| 341 | |
| 342 | To use the default disposition (attachment), leave the second parameter blank, |
| 343 | otherwise use a custom disposition:: |
| 344 | |
| 345 | $this->email->attach('image.jpg', 'inline'); |
| 346 | |
Andrey Andreev | ea801ab | 2014-01-20 15:03:43 +0200 | [diff] [blame] | 347 | You can also use a URL:: |
| 348 | |
| 349 | $this->email->attach('http://example.com/filename.pdf'); |
| 350 | |
Andrey Andreev | 71d8f72 | 2017-01-17 12:01:00 +0200 | [diff] [blame] | 351 | If you'd like to use a custom file name, you can use the third parameter:: |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 352 | |
| 353 | $this->email->attach('filename.pdf', 'attachment', 'report.pdf'); |
| 354 | |
| 355 | If you need to use a buffer string instead of a real - physical - file you can |
| 356 | use the first parameter as buffer, the third parameter as file name and the fourth |
| 357 | parameter as mime-type:: |
| 358 | |
| 359 | $this->email->attach($buffer, 'attachment', 'report.pdf', 'application/pdf'); |
| 360 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 361 | .. php:method:: attachment_cid($filename) |
Andrey Andreev | ea801ab | 2014-01-20 15:03:43 +0200 | [diff] [blame] | 362 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 363 | :param string $filename: Existing attachment filename |
| 364 | :returns: Attachment Content-ID or FALSE if not found |
| 365 | :rtype: string |
Andrey Andreev | ea801ab | 2014-01-20 15:03:43 +0200 | [diff] [blame] | 366 | |
| 367 | Sets and returns an attachment's Content-ID, which enables your to embed an inline |
| 368 | (picture) attachment into HTML. First parameter must be the already attached file name. |
| 369 | :: |
| 370 | |
| 371 | $filename = '/img/photo1.jpg'; |
| 372 | $this->email->attach($filename); |
| 373 | foreach ($list as $address) |
| 374 | { |
| 375 | $this->email->to($address); |
Andrey Andreev | 3022d17 | 2015-06-22 14:21:59 +0300 | [diff] [blame] | 376 | $cid = $this->email->attachment_cid($filename); |
Andrey Andreev | 98026f1 | 2016-04-12 21:15:38 +0300 | [diff] [blame] | 377 | $this->email->message('<img src="cid:'. $cid .'" alt="photo1" />'); |
Andrey Andreev | ea801ab | 2014-01-20 15:03:43 +0200 | [diff] [blame] | 378 | $this->email->send(); |
| 379 | } |
| 380 | |
| 381 | .. note:: Content-ID for each e-mail must be re-created for it to be unique. |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 382 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 383 | .. php:method:: print_debugger([$include = array('headers', 'subject', 'body')]) |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 384 | |
Andrey Andreev | 28c2c97 | 2014-02-08 04:27:48 +0200 | [diff] [blame] | 385 | :param array $include: Which parts of the message to print out |
| 386 | :returns: Formatted debug data |
| 387 | :rtype: string |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 388 | |
| 389 | Returns a string containing any server messages, the email headers, and |
Andrey Andreev | 71d8f72 | 2017-01-17 12:01:00 +0200 | [diff] [blame] | 390 | the email message. Useful for debugging. |
Derek Jones | d386f25 | 2013-07-24 17:35:45 -0700 | [diff] [blame] | 391 | |
| 392 | You can optionally specify which parts of the message should be printed. |
| 393 | Valid options are: **headers**, **subject**, **body**. |
| 394 | |
| 395 | Example:: |
| 396 | |
| 397 | // You need to pass FALSE while sending in order for the email data |
| 398 | // to not be cleared - if that happens, print_debugger() would have |
| 399 | // nothing to output. |
| 400 | $this->email->send(FALSE); |
| 401 | |
| 402 | // Will only print the email headers, excluding the message subject and body |
| 403 | $this->email->print_debugger(array('headers')); |
| 404 | |
| 405 | .. note:: By default, all of the raw data will be printed. |