Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like PHPMailer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PHPMailer, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
31 | class PHPMailer |
||
32 | { |
||
33 | /** |
||
34 | * Email priority. |
||
35 | * Options: null (default), 1 = High, 3 = Normal, 5 = low. |
||
36 | * When null, the header is not set at all. |
||
37 | * |
||
38 | * @var int |
||
39 | */ |
||
40 | public $Priority = null; |
||
41 | |||
42 | /** |
||
43 | * The character set of the message. |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | public $CharSet = 'iso-8859-1'; |
||
48 | |||
49 | /** |
||
50 | * The MIME Content-type of the message. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | public $ContentType = 'text/plain'; |
||
55 | |||
56 | /** |
||
57 | * The message encoding. |
||
58 | * Options: "8bit", "7bit", "binary", "base64", and "quoted-printable". |
||
59 | * |
||
60 | * @var string |
||
61 | */ |
||
62 | public $Encoding = '8bit'; |
||
63 | |||
64 | /** |
||
65 | * Holds the most recent mailer error message. |
||
66 | * |
||
67 | * @var string |
||
68 | */ |
||
69 | public $ErrorInfo = ''; |
||
70 | |||
71 | /** |
||
72 | * The From email address for the message. |
||
73 | * |
||
74 | * @var string |
||
75 | */ |
||
76 | public $From = 'root@localhost'; |
||
77 | |||
78 | /** |
||
79 | * The From name of the message. |
||
80 | * |
||
81 | * @var string |
||
82 | */ |
||
83 | public $FromName = 'Root User'; |
||
84 | |||
85 | /** |
||
86 | * The envelope sender of the message. |
||
87 | * This will usually be turned into a Return-Path header by the receiver, |
||
88 | * and is the address that bounces will be sent to. |
||
89 | * If not empty, will be passed via `-f` to sendmail or as the 'MAIL FROM' value over SMTP. |
||
90 | * |
||
91 | * @var string |
||
92 | */ |
||
93 | public $Sender = ''; |
||
94 | |||
95 | /** |
||
96 | * The Subject of the message. |
||
97 | * |
||
98 | * @var string |
||
99 | */ |
||
100 | public $Subject = ''; |
||
101 | |||
102 | /** |
||
103 | * An HTML or plain text message body. |
||
104 | * If HTML then call isHTML(true). |
||
105 | * |
||
106 | * @var string |
||
107 | */ |
||
108 | public $Body = ''; |
||
109 | |||
110 | /** |
||
111 | * The plain-text message body. |
||
112 | * This body can be read by mail clients that do not have HTML email |
||
113 | * capability such as mutt & Eudora. |
||
114 | * Clients that can read HTML will view the normal Body. |
||
115 | * |
||
116 | * @var string |
||
117 | */ |
||
118 | public $AltBody = ''; |
||
119 | |||
120 | /** |
||
121 | * An iCal message part body. |
||
122 | * Only supported in simple alt or alt_inline message types |
||
123 | * To generate iCal event structures, use classes like EasyPeasyICS or iCalcreator. |
||
124 | * |
||
125 | * @see http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/ |
||
126 | * @see http://kigkonsult.se/iCalcreator/ |
||
127 | * |
||
128 | * @var string |
||
129 | */ |
||
130 | public $Ical = ''; |
||
131 | |||
132 | /** |
||
133 | * The complete compiled MIME message body. |
||
134 | * |
||
135 | * @var string |
||
136 | */ |
||
137 | protected $MIMEBody = ''; |
||
138 | |||
139 | /** |
||
140 | * The complete compiled MIME message headers. |
||
141 | * |
||
142 | * @var string |
||
143 | */ |
||
144 | protected $MIMEHeader = ''; |
||
145 | |||
146 | /** |
||
147 | * Extra headers that createHeader() doesn't fold in. |
||
148 | * |
||
149 | * @var string |
||
150 | */ |
||
151 | protected $mailHeader = ''; |
||
152 | |||
153 | /** |
||
154 | * Word-wrap the message body to this number of chars. |
||
155 | * Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance. |
||
156 | * |
||
157 | * @see static::STD_LINE_LENGTH |
||
158 | * |
||
159 | * @var int |
||
160 | */ |
||
161 | public $WordWrap = 0; |
||
162 | |||
163 | /** |
||
164 | * Which method to use to send mail. |
||
165 | * Options: "mail", "sendmail", or "smtp". |
||
166 | * |
||
167 | * @var string |
||
168 | */ |
||
169 | public $Mailer = 'mail'; |
||
170 | |||
171 | /** |
||
172 | * The path to the sendmail program. |
||
173 | * |
||
174 | * @var string |
||
175 | */ |
||
176 | public $Sendmail = '/usr/sbin/sendmail'; |
||
177 | |||
178 | /** |
||
179 | * Whether mail() uses a fully sendmail-compatible MTA. |
||
180 | * One which supports sendmail's "-oi -f" options. |
||
181 | * |
||
182 | * @var bool |
||
183 | */ |
||
184 | public $UseSendmailOptions = true; |
||
185 | |||
186 | /** |
||
187 | * The email address that a reading confirmation should be sent to, also known as read receipt. |
||
188 | * |
||
189 | * @var string |
||
190 | */ |
||
191 | public $ConfirmReadingTo = ''; |
||
192 | |||
193 | /** |
||
194 | * The hostname to use in the Message-ID header and as default HELO string. |
||
195 | * If empty, PHPMailer attempts to find one with, in order, |
||
196 | * $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value |
||
197 | * 'localhost.localdomain'. |
||
198 | * |
||
199 | * @var string |
||
200 | */ |
||
201 | public $Hostname = ''; |
||
202 | |||
203 | /** |
||
204 | * An ID to be used in the Message-ID header. |
||
205 | * If empty, a unique id will be generated. |
||
206 | * You can set your own, but it must be in the format "<id@domain>", |
||
207 | * as defined in RFC5322 section 3.6.4 or it will be ignored. |
||
208 | * |
||
209 | * @see https://tools.ietf.org/html/rfc5322#section-3.6.4 |
||
210 | * |
||
211 | * @var string |
||
212 | */ |
||
213 | public $MessageID = ''; |
||
214 | |||
215 | /** |
||
216 | * The message Date to be used in the Date header. |
||
217 | * If empty, the current date will be added. |
||
218 | * |
||
219 | * @var string |
||
220 | */ |
||
221 | public $MessageDate = ''; |
||
222 | |||
223 | /** |
||
224 | * SMTP hosts. |
||
225 | * Either a single hostname or multiple semicolon-delimited hostnames. |
||
226 | * You can also specify a different port |
||
227 | * for each host by using this format: [hostname:port] |
||
228 | * (e.g. "smtp1.example.com:25;smtp2.example.com"). |
||
229 | * You can also specify encryption type, for example: |
||
230 | * (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465"). |
||
231 | * Hosts will be tried in order. |
||
232 | * |
||
233 | * @var string |
||
234 | */ |
||
235 | public $Host = 'localhost'; |
||
236 | |||
237 | /** |
||
238 | * The default SMTP server port. |
||
239 | * |
||
240 | * @var int |
||
241 | */ |
||
242 | public $Port = 25; |
||
243 | |||
244 | /** |
||
245 | * The SMTP HELO of the message. |
||
246 | * Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find |
||
247 | * one with the same method described above for $Hostname. |
||
248 | * |
||
249 | * @see PHPMailer::$Hostname |
||
250 | * |
||
251 | * @var string |
||
252 | */ |
||
253 | public $Helo = ''; |
||
254 | |||
255 | /** |
||
256 | * What kind of encryption to use on the SMTP connection. |
||
257 | * Options: '', 'ssl' or 'tls'. |
||
258 | * |
||
259 | * @var string |
||
260 | */ |
||
261 | public $SMTPSecure = ''; |
||
262 | |||
263 | /** |
||
264 | * Whether to enable TLS encryption automatically if a server supports it, |
||
265 | * even if `SMTPSecure` is not set to 'tls'. |
||
266 | * Be aware that in PHP >= 5.6 this requires that the server's certificates are valid. |
||
267 | * |
||
268 | * @var bool |
||
269 | */ |
||
270 | public $SMTPAutoTLS = true; |
||
271 | |||
272 | /** |
||
273 | * Whether to use SMTP authentication. |
||
274 | * Uses the Username and Password properties. |
||
275 | * |
||
276 | * @see PHPMailer::$Username |
||
277 | * @see PHPMailer::$Password |
||
278 | * |
||
279 | * @var bool |
||
280 | */ |
||
281 | public $SMTPAuth = false; |
||
282 | |||
283 | /** |
||
284 | * Options array passed to stream_context_create when connecting via SMTP. |
||
285 | * |
||
286 | * @var array |
||
287 | */ |
||
288 | public $SMTPOptions = []; |
||
289 | |||
290 | /** |
||
291 | * SMTP username. |
||
292 | * |
||
293 | * @var string |
||
294 | */ |
||
295 | public $Username = ''; |
||
296 | |||
297 | /** |
||
298 | * SMTP password. |
||
299 | * |
||
300 | * @var string |
||
301 | */ |
||
302 | public $Password = ''; |
||
303 | |||
304 | /** |
||
305 | * SMTP auth type. |
||
306 | * Options are CRAM-MD5, LOGIN, PLAIN, XOAUTH2, attempted in that order if not specified. |
||
307 | * |
||
308 | * @var string |
||
309 | */ |
||
310 | public $AuthType = ''; |
||
311 | |||
312 | /** |
||
313 | * An instance of the PHPMailer OAuth class. |
||
314 | * |
||
315 | * @var OAuth |
||
316 | */ |
||
317 | protected $oauth = null; |
||
318 | |||
319 | /** |
||
320 | * The SMTP server timeout in seconds. |
||
321 | * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2. |
||
322 | * |
||
323 | * @var int |
||
324 | */ |
||
325 | public $Timeout = 300; |
||
326 | |||
327 | /** |
||
328 | * SMTP class debug output mode. |
||
329 | * Debug output level. |
||
330 | * Options: |
||
331 | * * `0` No output |
||
332 | * * `1` Commands |
||
333 | * * `2` Data and commands |
||
334 | * * `3` As 2 plus connection status |
||
335 | * * `4` Low-level data output. |
||
336 | * |
||
337 | * @see SMTP::$do_debug |
||
338 | * |
||
339 | * @var int |
||
340 | */ |
||
341 | public $SMTPDebug = 0; |
||
342 | |||
343 | /** |
||
344 | * How to handle debug output. |
||
345 | * Options: |
||
346 | * * `echo` Output plain-text as-is, appropriate for CLI |
||
347 | * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output |
||
348 | * * `error_log` Output to error log as configured in php.ini |
||
349 | * By default PHPMailer will use `echo` if run from a `cli` or `cli-server` SAPI, `html` otherwise. |
||
350 | * Alternatively, you can provide a callable expecting two params: a message string and the debug level: |
||
351 | * |
||
352 | * ```php |
||
353 | * $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; |
||
354 | * ``` |
||
355 | * |
||
356 | * Alternatively, you can pass in an instance of a PSR-3 compatible logger, though only `debug` |
||
357 | * level output is used: |
||
358 | * |
||
359 | * ```php |
||
360 | * $mail->Debugoutput = new myPsr3Logger; |
||
361 | * ``` |
||
362 | * |
||
363 | * @see SMTP::$Debugoutput |
||
364 | * |
||
365 | * @var string|callable|\Psr\Log\LoggerInterface |
||
366 | */ |
||
367 | public $Debugoutput = 'echo'; |
||
368 | |||
369 | /** |
||
370 | * Whether to keep SMTP connection open after each message. |
||
371 | * If this is set to true then to close the connection |
||
372 | * requires an explicit call to smtpClose(). |
||
373 | * |
||
374 | * @var bool |
||
375 | */ |
||
376 | public $SMTPKeepAlive = false; |
||
377 | |||
378 | /** |
||
379 | * Whether to split multiple to addresses into multiple messages |
||
380 | * or send them all in one message. |
||
381 | * Only supported in `mail` and `sendmail` transports, not in SMTP. |
||
382 | * |
||
383 | * @var bool |
||
384 | */ |
||
385 | public $SingleTo = false; |
||
386 | |||
387 | /** |
||
388 | * Storage for addresses when SingleTo is enabled. |
||
389 | * |
||
390 | * @var array |
||
391 | */ |
||
392 | protected $SingleToArray = []; |
||
393 | |||
394 | /** |
||
395 | * Whether to generate VERP addresses on send. |
||
396 | * Only applicable when sending via SMTP. |
||
397 | * |
||
398 | * @see https://en.wikipedia.org/wiki/Variable_envelope_return_path |
||
399 | * @see http://www.postfix.org/VERP_README.html Postfix VERP info |
||
400 | * |
||
401 | * @var bool |
||
402 | */ |
||
403 | public $do_verp = false; |
||
404 | |||
405 | /** |
||
406 | * Whether to allow sending messages with an empty body. |
||
407 | * |
||
408 | * @var bool |
||
409 | */ |
||
410 | public $AllowEmpty = false; |
||
411 | |||
412 | /** |
||
413 | * DKIM selector. |
||
414 | * |
||
415 | * @var string |
||
416 | */ |
||
417 | public $DKIM_selector = ''; |
||
418 | |||
419 | /** |
||
420 | * DKIM Identity. |
||
421 | * Usually the email address used as the source of the email. |
||
422 | * |
||
423 | * @var string |
||
424 | */ |
||
425 | public $DKIM_identity = ''; |
||
426 | |||
427 | /** |
||
428 | * DKIM passphrase. |
||
429 | * Used if your key is encrypted. |
||
430 | * |
||
431 | * @var string |
||
432 | */ |
||
433 | public $DKIM_passphrase = ''; |
||
434 | |||
435 | /** |
||
436 | * DKIM signing domain name. |
||
437 | * |
||
438 | * @example 'example.com' |
||
439 | * |
||
440 | * @var string |
||
441 | */ |
||
442 | public $DKIM_domain = ''; |
||
443 | |||
444 | /** |
||
445 | * DKIM private key file path. |
||
446 | * |
||
447 | * @var string |
||
448 | */ |
||
449 | public $DKIM_private = ''; |
||
450 | |||
451 | /** |
||
452 | * DKIM private key string. |
||
453 | * |
||
454 | * If set, takes precedence over `$DKIM_private`. |
||
455 | * |
||
456 | * @var string |
||
457 | */ |
||
458 | public $DKIM_private_string = ''; |
||
459 | |||
460 | /** |
||
461 | * Callback Action function name. |
||
462 | * |
||
463 | * The function that handles the result of the send email action. |
||
464 | * It is called out by send() for each email sent. |
||
465 | * |
||
466 | * Value can be any php callable: http://www.php.net/is_callable |
||
467 | * |
||
468 | * Parameters: |
||
469 | * bool $result result of the send action |
||
470 | * array $to email addresses of the recipients |
||
471 | * array $cc cc email addresses |
||
472 | * array $bcc bcc email addresses |
||
473 | * string $subject the subject |
||
474 | * string $body the email body |
||
475 | * string $from email address of sender |
||
476 | * string $extra extra information of possible use |
||
477 | * "smtp_transaction_id' => last smtp transaction id |
||
478 | * |
||
479 | * @var string |
||
480 | */ |
||
481 | public $action_function = ''; |
||
482 | |||
483 | /** |
||
484 | * What to put in the X-Mailer header. |
||
485 | * Options: An empty string for PHPMailer default, whitespace for none, or a string to use. |
||
486 | * |
||
487 | * @var string |
||
488 | */ |
||
489 | public $XMailer = ''; |
||
490 | |||
491 | /** |
||
492 | * Which validator to use by default when validating email addresses. |
||
493 | * May be a callable to inject your own validator, but there are several built-in validators. |
||
494 | * The default validator uses PHP's FILTER_VALIDATE_EMAIL filter_var option. |
||
495 | * |
||
496 | * @see PHPMailer::validateAddress() |
||
497 | * |
||
498 | * @var string|callable |
||
499 | */ |
||
500 | public static $validator = 'php'; |
||
501 | |||
502 | /** |
||
503 | * An instance of the SMTP sender class. |
||
504 | * |
||
505 | * @var SMTP |
||
506 | */ |
||
507 | protected $smtp = null; |
||
508 | |||
509 | /** |
||
510 | * The array of 'to' names and addresses. |
||
511 | * |
||
512 | * @var array |
||
513 | */ |
||
514 | protected $to = []; |
||
515 | |||
516 | /** |
||
517 | * The array of 'cc' names and addresses. |
||
518 | * |
||
519 | * @var array |
||
520 | */ |
||
521 | protected $cc = []; |
||
522 | |||
523 | /** |
||
524 | * The array of 'bcc' names and addresses. |
||
525 | * |
||
526 | * @var array |
||
527 | */ |
||
528 | protected $bcc = []; |
||
529 | |||
530 | /** |
||
531 | * The array of reply-to names and addresses. |
||
532 | * |
||
533 | * @var array |
||
534 | */ |
||
535 | protected $ReplyTo = []; |
||
536 | |||
537 | /** |
||
538 | * An array of all kinds of addresses. |
||
539 | * Includes all of $to, $cc, $bcc. |
||
540 | * |
||
541 | * @see PHPMailer::$to |
||
542 | * @see PHPMailer::$cc |
||
543 | * @see PHPMailer::$bcc |
||
544 | * |
||
545 | * @var array |
||
546 | */ |
||
547 | protected $all_recipients = []; |
||
548 | |||
549 | /** |
||
550 | * An array of names and addresses queued for validation. |
||
551 | * In send(), valid and non duplicate entries are moved to $all_recipients |
||
552 | * and one of $to, $cc, or $bcc. |
||
553 | * This array is used only for addresses with IDN. |
||
554 | * |
||
555 | * @see PHPMailer::$to |
||
556 | * @see PHPMailer::$cc |
||
557 | * @see PHPMailer::$bcc |
||
558 | * @see PHPMailer::$all_recipients |
||
559 | * |
||
560 | * @var array |
||
561 | */ |
||
562 | protected $RecipientsQueue = []; |
||
563 | |||
564 | /** |
||
565 | * An array of reply-to names and addresses queued for validation. |
||
566 | * In send(), valid and non duplicate entries are moved to $ReplyTo. |
||
567 | * This array is used only for addresses with IDN. |
||
568 | * |
||
569 | * @see PHPMailer::$ReplyTo |
||
570 | * |
||
571 | * @var array |
||
572 | */ |
||
573 | protected $ReplyToQueue = []; |
||
574 | |||
575 | /** |
||
576 | * The array of attachments. |
||
577 | * |
||
578 | * @var array |
||
579 | */ |
||
580 | protected $attachment = []; |
||
581 | |||
582 | /** |
||
583 | * The array of custom headers. |
||
584 | * |
||
585 | * @var array |
||
586 | */ |
||
587 | protected $CustomHeader = []; |
||
588 | |||
589 | /** |
||
590 | * The most recent Message-ID (including angular brackets). |
||
591 | * |
||
592 | * @var string |
||
593 | */ |
||
594 | protected $lastMessageID = ''; |
||
595 | |||
596 | /** |
||
597 | * The message's MIME type. |
||
598 | * |
||
599 | * @var string |
||
600 | */ |
||
601 | protected $message_type = ''; |
||
602 | |||
603 | /** |
||
604 | * The array of MIME boundary strings. |
||
605 | * |
||
606 | * @var array |
||
607 | */ |
||
608 | protected $boundary = []; |
||
609 | |||
610 | /** |
||
611 | * The array of available languages. |
||
612 | * |
||
613 | * @var array |
||
614 | */ |
||
615 | protected $language = []; |
||
616 | |||
617 | /** |
||
618 | * The number of errors encountered. |
||
619 | * |
||
620 | * @var int |
||
621 | */ |
||
622 | protected $error_count = 0; |
||
623 | |||
624 | /** |
||
625 | * The S/MIME certificate file path. |
||
626 | * |
||
627 | * @var string |
||
628 | */ |
||
629 | protected $sign_cert_file = ''; |
||
630 | |||
631 | /** |
||
632 | * The S/MIME key file path. |
||
633 | * |
||
634 | * @var string |
||
635 | */ |
||
636 | protected $sign_key_file = ''; |
||
637 | |||
638 | /** |
||
639 | * The optional S/MIME extra certificates ("CA Chain") file path. |
||
640 | * |
||
641 | * @var string |
||
642 | */ |
||
643 | protected $sign_extracerts_file = ''; |
||
644 | |||
645 | /** |
||
646 | * The S/MIME password for the key. |
||
647 | * Used only if the key is encrypted. |
||
648 | * |
||
649 | * @var string |
||
650 | */ |
||
651 | protected $sign_key_pass = ''; |
||
652 | |||
653 | /** |
||
654 | * Whether to throw exceptions for errors. |
||
655 | * |
||
656 | * @var bool |
||
657 | */ |
||
658 | protected $exceptions = false; |
||
659 | |||
660 | /** |
||
661 | * Unique ID used for message ID and boundaries. |
||
662 | * |
||
663 | * @var string |
||
664 | */ |
||
665 | protected $uniqueid = ''; |
||
666 | |||
667 | /** |
||
668 | * The PHPMailer Version number. |
||
669 | * |
||
670 | * @var string |
||
671 | */ |
||
672 | const VERSION = '6.0.1'; |
||
673 | |||
674 | /** |
||
675 | * Error severity: message only, continue processing. |
||
676 | * |
||
677 | * @var int |
||
678 | */ |
||
679 | const STOP_MESSAGE = 0; |
||
680 | |||
681 | /** |
||
682 | * Error severity: message, likely ok to continue processing. |
||
683 | * |
||
684 | * @var int |
||
685 | */ |
||
686 | const STOP_CONTINUE = 1; |
||
687 | |||
688 | /** |
||
689 | * Error severity: message, plus full stop, critical error reached. |
||
690 | * |
||
691 | * @var int |
||
692 | */ |
||
693 | const STOP_CRITICAL = 2; |
||
694 | |||
695 | /** |
||
696 | * SMTP RFC standard line ending. |
||
697 | * |
||
698 | * @var string |
||
699 | */ |
||
700 | protected static $LE = "\r\n"; |
||
701 | |||
702 | /** |
||
703 | * The maximum line length allowed by RFC 2822 section 2.1.1. |
||
704 | * |
||
705 | * @var int |
||
706 | */ |
||
707 | const MAX_LINE_LENGTH = 998; |
||
708 | |||
709 | /** |
||
710 | * The lower maximum line length allowed by RFC 2822 section 2.1.1. |
||
711 | * |
||
712 | * @var int |
||
713 | */ |
||
714 | const STD_LINE_LENGTH = 78; |
||
715 | |||
716 | /** |
||
717 | * Constructor. |
||
718 | * |
||
719 | * @param bool $exceptions Should we throw external exceptions? |
||
720 | */ |
||
721 | public function __construct($exceptions = null) |
||
729 | |||
730 | /** |
||
731 | * Destructor. |
||
732 | */ |
||
733 | public function __destruct() |
||
738 | |||
739 | /** |
||
740 | * Call mail() in a safe_mode-aware fashion. |
||
741 | * Also, unless sendmail_path points to sendmail (or something that |
||
742 | * claims to be sendmail), don't pass params (not a perfect fix, |
||
743 | * but it will do). |
||
744 | * |
||
745 | * @param string $to To |
||
746 | * @param string $subject Subject |
||
747 | * @param string $body Message Body |
||
748 | * @param string $header Additional Header(s) |
||
749 | * @param string|null $params Params |
||
750 | * |
||
751 | * @return bool |
||
752 | */ |
||
753 | private function mailPassthru($to, $subject, $body, $header, $params) |
||
770 | |||
771 | /** |
||
772 | * Output debugging info via user-defined method. |
||
773 | * Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug). |
||
774 | * |
||
775 | * @see PHPMailer::$Debugoutput |
||
776 | * @see PHPMailer::$SMTPDebug |
||
777 | * |
||
778 | * @param string $str |
||
779 | */ |
||
780 | protected function edebug($str) |
||
828 | |||
829 | /** |
||
830 | * Sets message type to HTML or plain. |
||
831 | * |
||
832 | * @param bool $isHtml True for HTML mode |
||
833 | */ |
||
834 | public function isHTML($isHtml = true) |
||
842 | |||
843 | /** |
||
844 | * Send messages using SMTP. |
||
845 | */ |
||
846 | public function isSMTP() |
||
850 | |||
851 | /** |
||
852 | * Send messages using PHP's mail() function. |
||
853 | */ |
||
854 | public function isMail() |
||
858 | |||
859 | /** |
||
860 | * Send messages using $Sendmail. |
||
861 | */ |
||
862 | View Code Duplication | public function isSendmail() |
|
873 | |||
874 | /** |
||
875 | * Send messages using qmail. |
||
876 | */ |
||
877 | View Code Duplication | public function isQmail() |
|
888 | |||
889 | /** |
||
890 | * Add a "To" address. |
||
891 | * |
||
892 | * @param string $address The email address to send to |
||
893 | * @param string $name |
||
894 | * |
||
895 | * @return bool true on success, false if address already used or invalid in some way |
||
896 | */ |
||
897 | public function addAddress($address, $name = '') |
||
901 | |||
902 | /** |
||
903 | * Add a "CC" address. |
||
904 | * |
||
905 | * @param string $address The email address to send to |
||
906 | * @param string $name |
||
907 | * |
||
908 | * @return bool true on success, false if address already used or invalid in some way |
||
909 | */ |
||
910 | public function addCC($address, $name = '') |
||
914 | |||
915 | /** |
||
916 | * Add a "BCC" address. |
||
917 | * |
||
918 | * @param string $address The email address to send to |
||
919 | * @param string $name |
||
920 | * |
||
921 | * @return bool true on success, false if address already used or invalid in some way |
||
922 | */ |
||
923 | public function addBCC($address, $name = '') |
||
927 | |||
928 | /** |
||
929 | * Add a "Reply-To" address. |
||
930 | * |
||
931 | * @param string $address The email address to reply to |
||
932 | * @param string $name |
||
933 | * |
||
934 | * @return bool true on success, false if address already used or invalid in some way |
||
935 | */ |
||
936 | public function addReplyTo($address, $name = '') |
||
940 | |||
941 | /** |
||
942 | * Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer |
||
943 | * can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still |
||
944 | * be modified after calling this function), addition of such addresses is delayed until send(). |
||
945 | * Addresses that have been added already return false, but do not throw exceptions. |
||
946 | * |
||
947 | * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo' |
||
948 | * @param string $address The email address to send, resp. to reply to |
||
949 | * @param string $name |
||
950 | * |
||
951 | * @throws Exception |
||
952 | * |
||
953 | * @return bool true on success, false if address already used or invalid in some way |
||
954 | */ |
||
955 | protected function addOrEnqueueAnAddress($kind, $address, $name) |
||
994 | |||
995 | /** |
||
996 | * Add an address to one of the recipient arrays or to the ReplyTo array. |
||
997 | * Addresses that have been added already return false, but do not throw exceptions. |
||
998 | * |
||
999 | * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo' |
||
1000 | * @param string $address The email address to send, resp. to reply to |
||
1001 | * @param string $name |
||
1002 | * |
||
1003 | * @throws Exception |
||
1004 | * |
||
1005 | * @return bool true on success, false if address already used or invalid in some way |
||
1006 | */ |
||
1007 | protected function addAnAddress($kind, $address, $name = '') |
||
1046 | |||
1047 | /** |
||
1048 | * Parse and validate a string containing one or more RFC822-style comma-separated email addresses |
||
1049 | * of the form "display name <address>" into an array of name/address pairs. |
||
1050 | * Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. |
||
1051 | * Note that quotes in the name part are removed. |
||
1052 | * |
||
1053 | * @see http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation |
||
1054 | * |
||
1055 | * @param string $addrstr The address list string |
||
1056 | * @param bool $useimap Whether to use the IMAP extension to parse the list |
||
1057 | * |
||
1058 | * @return array |
||
1059 | */ |
||
1060 | public static function parseAddresses($addrstr, $useimap = true) |
||
1105 | |||
1106 | /** |
||
1107 | * Set the From and FromName properties. |
||
1108 | * |
||
1109 | * @param string $address |
||
1110 | * @param string $name |
||
1111 | * @param bool $auto Whether to also set the Sender address, defaults to true |
||
1112 | * |
||
1113 | * @throws Exception |
||
1114 | * |
||
1115 | * @return bool |
||
1116 | */ |
||
1117 | public function setFrom($address, $name = '', $auto = true) |
||
1145 | |||
1146 | /** |
||
1147 | * Return the Message-ID header of the last email. |
||
1148 | * Technically this is the value from the last time the headers were created, |
||
1149 | * but it's also the message ID of the last sent message except in |
||
1150 | * pathological cases. |
||
1151 | * |
||
1152 | * @return string |
||
1153 | */ |
||
1154 | public function getLastMessageID() |
||
1158 | |||
1159 | /** |
||
1160 | * Check that a string looks like an email address. |
||
1161 | * Validation patterns supported: |
||
1162 | * * `auto` Pick best pattern automatically; |
||
1163 | * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0; |
||
1164 | * * `pcre` Use old PCRE implementation; |
||
1165 | * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; |
||
1166 | * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements. |
||
1167 | * * `noregex` Don't use a regex: super fast, really dumb. |
||
1168 | * Alternatively you may pass in a callable to inject your own validator, for example: |
||
1169 | * |
||
1170 | * ```php |
||
1171 | * PHPMailer::validateAddress('[email protected]', function($address) { |
||
1172 | * return (strpos($address, '@') !== false); |
||
1173 | * }); |
||
1174 | * ``` |
||
1175 | * |
||
1176 | * You can also set the PHPMailer::$validator static to a callable, allowing built-in methods to use your validator. |
||
1177 | * |
||
1178 | * @param string $address The email address to check |
||
1179 | * @param string|callable $patternselect Which pattern to use |
||
1180 | * |
||
1181 | * @return bool |
||
1182 | */ |
||
1183 | public static function validateAddress($address, $patternselect = null) |
||
1242 | |||
1243 | /** |
||
1244 | * Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the |
||
1245 | * `intl` and `mbstring` PHP extensions. |
||
1246 | * |
||
1247 | * @return bool `true` if required functions for IDN support are present |
||
1248 | */ |
||
1249 | public function idnSupported() |
||
1253 | |||
1254 | /** |
||
1255 | * Converts IDN in given email address to its ASCII form, also known as punycode, if possible. |
||
1256 | * Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet. |
||
1257 | * This function silently returns unmodified address if: |
||
1258 | * - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form) |
||
1259 | * - Conversion to punycode is impossible (e.g. required PHP functions are not available) |
||
1260 | * or fails for any reason (e.g. domain contains characters not allowed in an IDN). |
||
1261 | * |
||
1262 | * @see PHPMailer::$CharSet |
||
1263 | * |
||
1264 | * @param string $address The email address to convert |
||
1265 | * |
||
1266 | * @return string The encoded address in ASCII form |
||
1267 | */ |
||
1268 | public function punyencodeAddress($address) |
||
1291 | |||
1292 | /** |
||
1293 | * Create a message and send it. |
||
1294 | * Uses the sending method specified by $Mailer. |
||
1295 | * |
||
1296 | * @throws Exception |
||
1297 | * |
||
1298 | * @return bool false on error - See the ErrorInfo property for details of the error |
||
1299 | */ |
||
1300 | public function send() |
||
1318 | |||
1319 | /** |
||
1320 | * Prepare a message for sending. |
||
1321 | * |
||
1322 | * @throws Exception |
||
1323 | * |
||
1324 | * @return bool |
||
1325 | */ |
||
1326 | public function preSend() |
||
1448 | |||
1449 | /** |
||
1450 | * Actually send a message via the selected mechanism. |
||
1451 | * |
||
1452 | * @throws Exception |
||
1453 | * |
||
1454 | * @return bool |
||
1455 | */ |
||
1456 | public function postSend() |
||
1486 | |||
1487 | /** |
||
1488 | * Send mail using the $Sendmail program. |
||
1489 | * |
||
1490 | * @see PHPMailer::$Sendmail |
||
1491 | * |
||
1492 | * @param string $header The message headers |
||
1493 | * @param string $body The message body |
||
1494 | * |
||
1495 | * @throws Exception |
||
1496 | * |
||
1497 | * @return bool |
||
1498 | */ |
||
1499 | protected function sendmailSend($header, $body) |
||
1567 | |||
1568 | /** |
||
1569 | * Fix CVE-2016-10033 and CVE-2016-10045 by disallowing potentially unsafe shell characters. |
||
1570 | * Note that escapeshellarg and escapeshellcmd are inadequate for our purposes, especially on Windows. |
||
1571 | * |
||
1572 | * @see https://github.com/PHPMailer/PHPMailer/issues/924 CVE-2016-10045 bug report |
||
1573 | * |
||
1574 | * @param string $string The string to be validated |
||
1575 | * |
||
1576 | * @return bool |
||
1577 | */ |
||
1578 | protected static function isShellSafe($string) |
||
1602 | |||
1603 | /** |
||
1604 | * Send mail using the PHP mail() function. |
||
1605 | * |
||
1606 | * @see http://www.php.net/manual/en/book.mail.php |
||
1607 | * |
||
1608 | * @param string $header The message headers |
||
1609 | * @param string $body The message body |
||
1610 | * |
||
1611 | * @throws Exception |
||
1612 | * |
||
1613 | * @return bool |
||
1614 | */ |
||
1615 | protected function mailSend($header, $body) |
||
1660 | |||
1661 | /** |
||
1662 | * Get an instance to use for SMTP operations. |
||
1663 | * Override this function to load your own SMTP implementation, |
||
1664 | * or set one with setSMTPInstance. |
||
1665 | * |
||
1666 | * @return SMTP |
||
1667 | */ |
||
1668 | public function getSMTPInstance() |
||
1676 | |||
1677 | /** |
||
1678 | * Provide an instance to use for SMTP operations. |
||
1679 | * |
||
1680 | * @param SMTP $smtp |
||
1681 | * |
||
1682 | * @return SMTP |
||
1683 | */ |
||
1684 | public function setSMTPInstance(SMTP $smtp) |
||
1690 | |||
1691 | /** |
||
1692 | * Send mail via SMTP. |
||
1693 | * Returns false if there is a bad MAIL FROM, RCPT, or DATA input. |
||
1694 | * |
||
1695 | * @see PHPMailer::setSMTPInstance() to use a different class. |
||
1696 | * |
||
1697 | * @uses \PHPMailer\PHPMailer\SMTP |
||
1698 | * |
||
1699 | * @param string $header The message headers |
||
1700 | * @param string $body The message body |
||
1701 | * |
||
1702 | * @throws Exception |
||
1703 | * |
||
1704 | * @return bool |
||
1705 | */ |
||
1706 | protected function smtpSend($header, $body) |
||
1780 | |||
1781 | /** |
||
1782 | * Initiate a connection to an SMTP server. |
||
1783 | * Returns false if the operation failed. |
||
1784 | * |
||
1785 | * @param array $options An array of options compatible with stream_context_create() |
||
1786 | * |
||
1787 | * @throws Exception |
||
1788 | * |
||
1789 | * @uses \PHPMailer\PHPMailer\SMTP |
||
1790 | * |
||
1791 | * @return bool |
||
1792 | */ |
||
1793 | public function smtpConnect($options = null) |
||
1917 | |||
1918 | /** |
||
1919 | * Close the active SMTP session if one exists. |
||
1920 | */ |
||
1921 | public function smtpClose() |
||
1930 | |||
1931 | /** |
||
1932 | * Set the language for error messages. |
||
1933 | * Returns false if it cannot load the language file. |
||
1934 | * The default language is English. |
||
1935 | * |
||
1936 | * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr") |
||
1937 | * @param string $lang_path Path to the language file directory, with trailing separator (slash) |
||
1938 | * |
||
1939 | * @return bool |
||
1940 | */ |
||
1941 | public function setLanguage($langcode = 'en', $lang_path = '') |
||
2004 | |||
2005 | /** |
||
2006 | * Get the array of strings for the current language. |
||
2007 | * |
||
2008 | * @return array |
||
2009 | */ |
||
2010 | public function getTranslations() |
||
2014 | |||
2015 | /** |
||
2016 | * Create recipient headers. |
||
2017 | * |
||
2018 | * @param string $type |
||
2019 | * @param array $addr An array of recipients, |
||
2020 | * where each recipient is a 2-element indexed array with element 0 containing an address |
||
2021 | * and element 1 containing a name, like: |
||
2022 | * [['[email protected]', 'Joe User'], ['[email protected]', 'Zoe User']] |
||
2023 | * |
||
2024 | * @return string |
||
2025 | */ |
||
2026 | public function addrAppend($type, $addr) |
||
2035 | |||
2036 | /** |
||
2037 | * Format an address for use in a message header. |
||
2038 | * |
||
2039 | * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name like |
||
2040 | * ['[email protected]', 'Joe User'] |
||
2041 | * |
||
2042 | * @return string |
||
2043 | */ |
||
2044 | public function addrFormat($addr) |
||
2054 | |||
2055 | /** |
||
2056 | * Word-wrap message. |
||
2057 | * For use with mailers that do not automatically perform wrapping |
||
2058 | * and for quoted-printable encoded messages. |
||
2059 | * Original written by philippe. |
||
2060 | * |
||
2061 | * @param string $message The message to wrap |
||
2062 | * @param int $length The line length to wrap to |
||
2063 | * @param bool $qp_mode Whether to run in Quoted-Printable mode |
||
2064 | * |
||
2065 | * @return string |
||
2066 | */ |
||
2067 | public function wrapText($message, $length, $qp_mode = false) |
||
2156 | |||
2157 | /** |
||
2158 | * Find the last character boundary prior to $maxLength in a utf-8 |
||
2159 | * quoted-printable encoded string. |
||
2160 | * Original written by Colin Brown. |
||
2161 | * |
||
2162 | * @param string $encodedText utf-8 QP text |
||
2163 | * @param int $maxLength Find the last character boundary prior to this length |
||
2164 | * |
||
2165 | * @return int |
||
2166 | */ |
||
2167 | public function utf8CharBoundary($encodedText, $maxLength) |
||
2204 | |||
2205 | /** |
||
2206 | * Apply word wrapping to the message body. |
||
2207 | * Wraps the message body to the number of chars set in the WordWrap property. |
||
2208 | * You should only do this to plain-text bodies as wrapping HTML tags may break them. |
||
2209 | * This is called automatically by createBody(), so you don't need to call it yourself. |
||
2210 | */ |
||
2211 | public function setWordWrap() |
||
2229 | |||
2230 | /** |
||
2231 | * Assemble message headers. |
||
2232 | * |
||
2233 | * @return string The assembled headers |
||
2234 | */ |
||
2235 | public function createHeader() |
||
2324 | |||
2325 | /** |
||
2326 | * Get the message MIME type headers. |
||
2327 | * |
||
2328 | * @return string |
||
2329 | */ |
||
2330 | public function getMailMIME() |
||
2376 | |||
2377 | /** |
||
2378 | * Returns the whole MIME message. |
||
2379 | * Includes complete headers and body. |
||
2380 | * Only valid post preSend(). |
||
2381 | * |
||
2382 | * @see PHPMailer::preSend() |
||
2383 | * |
||
2384 | * @return string |
||
2385 | */ |
||
2386 | public function getSentMIMEMessage() |
||
2390 | |||
2391 | /** |
||
2392 | * Create a unique ID to use for boundaries. |
||
2393 | * |
||
2394 | * @return string |
||
2395 | */ |
||
2396 | protected function generateId() |
||
2411 | |||
2412 | /** |
||
2413 | * Assemble the message body. |
||
2414 | * Returns an empty string on failure. |
||
2415 | * |
||
2416 | * @throws Exception |
||
2417 | * |
||
2418 | * @return string The assembled message body |
||
2419 | */ |
||
2420 | public function createBody() |
||
2631 | |||
2632 | /** |
||
2633 | * Return the start of a message boundary. |
||
2634 | * |
||
2635 | * @param string $boundary |
||
2636 | * @param string $charSet |
||
2637 | * @param string $contentType |
||
2638 | * @param string $encoding |
||
2639 | * |
||
2640 | * @return string |
||
2641 | */ |
||
2642 | protected function getBoundary($boundary, $charSet, $contentType, $encoding) |
||
2665 | |||
2666 | /** |
||
2667 | * Return the end of a message boundary. |
||
2668 | * |
||
2669 | * @param string $boundary |
||
2670 | * |
||
2671 | * @return string |
||
2672 | */ |
||
2673 | protected function endBoundary($boundary) |
||
2677 | |||
2678 | /** |
||
2679 | * Set the message type. |
||
2680 | * PHPMailer only supports some preset message types, not arbitrary MIME structures. |
||
2681 | */ |
||
2682 | protected function setMessageType() |
||
2700 | |||
2701 | /** |
||
2702 | * Format a header line. |
||
2703 | * |
||
2704 | * @param string $name |
||
2705 | * @param string|int $value |
||
2706 | * |
||
2707 | * @return string |
||
2708 | */ |
||
2709 | public function headerLine($name, $value) |
||
2713 | |||
2714 | /** |
||
2715 | * Return a formatted mail line. |
||
2716 | * |
||
2717 | * @param string $value |
||
2718 | * |
||
2719 | * @return string |
||
2720 | */ |
||
2721 | public function textLine($value) |
||
2725 | |||
2726 | /** |
||
2727 | * Add an attachment from a path on the filesystem. |
||
2728 | * Never use a user-supplied path to a file! |
||
2729 | * Returns false if the file could not be found or read. |
||
2730 | * |
||
2731 | * @param string $path Path to the attachment |
||
2732 | * @param string $name Overrides the attachment name |
||
2733 | * @param string $encoding File encoding (see $Encoding) |
||
2734 | * @param string $type File extension (MIME) type |
||
2735 | * @param string $disposition Disposition to use |
||
2736 | * |
||
2737 | * @throws Exception |
||
2738 | * |
||
2739 | * @return bool |
||
2740 | */ |
||
2741 | public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment') |
||
2780 | |||
2781 | /** |
||
2782 | * Return the array of attachments. |
||
2783 | * |
||
2784 | * @return array |
||
2785 | */ |
||
2786 | public function getAttachments() |
||
2790 | |||
2791 | /** |
||
2792 | * Attach all file, string, and binary attachments to the message. |
||
2793 | * Returns an empty string on failure. |
||
2794 | * |
||
2795 | * @param string $disposition_type |
||
2796 | * @param string $boundary |
||
2797 | * |
||
2798 | * @return string |
||
2799 | */ |
||
2800 | protected function attachAll($disposition_type, $boundary) |
||
2911 | |||
2912 | /** |
||
2913 | * Encode a file attachment in requested format. |
||
2914 | * Returns an empty string on failure. |
||
2915 | * |
||
2916 | * @param string $path The full path to the file |
||
2917 | * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' |
||
2918 | * |
||
2919 | * @throws Exception |
||
2920 | * |
||
2921 | * @return string |
||
2922 | */ |
||
2923 | protected function encodeFile($path, $encoding = 'base64') |
||
2942 | |||
2943 | /** |
||
2944 | * Encode a string in requested format. |
||
2945 | * Returns an empty string on failure. |
||
2946 | * |
||
2947 | * @param string $str The text to encode |
||
2948 | * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable |
||
2949 | * |
||
2950 | * @return string |
||
2951 | */ |
||
2952 | public function encodeString($str, $encoding = 'base64') |
||
2984 | |||
2985 | /** |
||
2986 | * Encode a header value (not including its label) optimally. |
||
2987 | * Picks shortest of Q, B, or none. Result includes folding if needed. |
||
2988 | * See RFC822 definitions for phrase, comment and text positions. |
||
2989 | * |
||
2990 | * @param string $str The header value to encode |
||
2991 | * @param string $position What context the string will be used in |
||
2992 | * |
||
2993 | * @return string |
||
2994 | */ |
||
2995 | public function encodeHeader($str, $position = 'text') |
||
3070 | |||
3071 | /** |
||
3072 | * Check if a string contains multi-byte characters. |
||
3073 | * |
||
3074 | * @param string $str multi-byte text to wrap encode |
||
3075 | * |
||
3076 | * @return bool |
||
3077 | */ |
||
3078 | public function hasMultiBytes($str) |
||
3087 | |||
3088 | /** |
||
3089 | * Does a string contain any 8-bit chars (in any charset)? |
||
3090 | * |
||
3091 | * @param string $text |
||
3092 | * |
||
3093 | * @return bool |
||
3094 | */ |
||
3095 | public function has8bitChars($text) |
||
3099 | |||
3100 | /** |
||
3101 | * Encode and wrap long multibyte strings for mail headers |
||
3102 | * without breaking lines within a character. |
||
3103 | * Adapted from a function by paravoid. |
||
3104 | * |
||
3105 | * @see http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283 |
||
3106 | * |
||
3107 | * @param string $str multi-byte text to wrap encode |
||
3108 | * @param string $linebreak string to use as linefeed/end-of-line |
||
3109 | * |
||
3110 | * @return string |
||
3111 | */ |
||
3112 | public function base64EncodeWrapMB($str, $linebreak = null) |
||
3143 | |||
3144 | /** |
||
3145 | * Encode a string in quoted-printable format. |
||
3146 | * According to RFC2045 section 6.7. |
||
3147 | * |
||
3148 | * @param string $string The text to encode |
||
3149 | * |
||
3150 | * @return string |
||
3151 | */ |
||
3152 | public function encodeQP($string) |
||
3156 | |||
3157 | /** |
||
3158 | * Encode a string using Q encoding. |
||
3159 | * |
||
3160 | * @see http://tools.ietf.org/html/rfc2047#section-4.2 |
||
3161 | * |
||
3162 | * @param string $str the text to encode |
||
3163 | * @param string $position Where the text is going to be used, see the RFC for what that means |
||
3164 | * |
||
3165 | * @return string |
||
3166 | */ |
||
3167 | public function encodeQ($str, $position = 'text') |
||
3209 | |||
3210 | /** |
||
3211 | * Add a string or binary attachment (non-filesystem). |
||
3212 | * This method can be used to attach ascii or binary data, |
||
3213 | * such as a BLOB record from a database. |
||
3214 | * |
||
3215 | * @param string $string String attachment data |
||
3216 | * @param string $filename Name of the attachment |
||
3217 | * @param string $encoding File encoding (see $Encoding) |
||
3218 | * @param string $type File extension (MIME) type |
||
3219 | * @param string $disposition Disposition to use |
||
3220 | */ |
||
3221 | public function addStringAttachment( |
||
3244 | |||
3245 | /** |
||
3246 | * Add an embedded (inline) attachment from a file. |
||
3247 | * This can include images, sounds, and just about any other document type. |
||
3248 | * These differ from 'regular' attachments in that they are intended to be |
||
3249 | * displayed inline with the message, not just attached for download. |
||
3250 | * This is used in HTML messages that embed the images |
||
3251 | * the HTML refers to using the $cid value. |
||
3252 | * Never use a user-supplied path to a file! |
||
3253 | * |
||
3254 | * @param string $path Path to the attachment |
||
3255 | * @param string $cid Content ID of the attachment; Use this to reference |
||
3256 | * the content when using an embedded image in HTML |
||
3257 | * @param string $name Overrides the attachment name |
||
3258 | * @param string $encoding File encoding (see $Encoding) |
||
3259 | * @param string $type File MIME type |
||
3260 | * @param string $disposition Disposition to use |
||
3261 | * |
||
3262 | * @return bool True on successfully adding an attachment |
||
3263 | */ |
||
3264 | public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline') |
||
3296 | |||
3297 | /** |
||
3298 | * Add an embedded stringified attachment. |
||
3299 | * This can include images, sounds, and just about any other document type. |
||
3300 | * Be sure to set the $type to an image type for images: |
||
3301 | * JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'. |
||
3302 | * |
||
3303 | * @param string $string The attachment binary data |
||
3304 | * @param string $cid Content ID of the attachment; Use this to reference |
||
3305 | * the content when using an embedded image in HTML |
||
3306 | * @param string $name |
||
3307 | * @param string $encoding File encoding (see $Encoding) |
||
3308 | * @param string $type MIME type |
||
3309 | * @param string $disposition Disposition to use |
||
3310 | * |
||
3311 | * @return bool True on successfully adding an attachment |
||
3312 | */ |
||
3313 | public function addStringEmbeddedImage( |
||
3340 | |||
3341 | /** |
||
3342 | * Check if an embedded attachment is present with this cid. |
||
3343 | * |
||
3344 | * @param string $cid |
||
3345 | * |
||
3346 | * @return bool |
||
3347 | */ |
||
3348 | View Code Duplication | protected function cidExists($cid) |
|
3358 | |||
3359 | /** |
||
3360 | * Check if an inline attachment is present. |
||
3361 | * |
||
3362 | * @return bool |
||
3363 | */ |
||
3364 | View Code Duplication | public function inlineImageExists() |
|
3374 | |||
3375 | /** |
||
3376 | * Check if an attachment (non-inline) is present. |
||
3377 | * |
||
3378 | * @return bool |
||
3379 | */ |
||
3380 | public function attachmentExists() |
||
3390 | |||
3391 | /** |
||
3392 | * Check if this message has an alternative body set. |
||
3393 | * |
||
3394 | * @return bool |
||
3395 | */ |
||
3396 | public function alternativeExists() |
||
3400 | |||
3401 | /** |
||
3402 | * Clear queued addresses of given kind. |
||
3403 | * |
||
3404 | * @param string $kind 'to', 'cc', or 'bcc' |
||
3405 | */ |
||
3406 | public function clearQueuedAddresses($kind) |
||
3415 | |||
3416 | /** |
||
3417 | * Clear all To recipients. |
||
3418 | */ |
||
3419 | public function clearAddresses() |
||
3427 | |||
3428 | /** |
||
3429 | * Clear all CC recipients. |
||
3430 | */ |
||
3431 | View Code Duplication | public function clearCCs() |
|
3439 | |||
3440 | /** |
||
3441 | * Clear all BCC recipients. |
||
3442 | */ |
||
3443 | View Code Duplication | public function clearBCCs() |
|
3451 | |||
3452 | /** |
||
3453 | * Clear all ReplyTo recipients. |
||
3454 | */ |
||
3455 | public function clearReplyTos() |
||
3460 | |||
3461 | /** |
||
3462 | * Clear all recipient types. |
||
3463 | */ |
||
3464 | public function clearAllRecipients() |
||
3472 | |||
3473 | /** |
||
3474 | * Clear all filesystem, string, and binary attachments. |
||
3475 | */ |
||
3476 | public function clearAttachments() |
||
3480 | |||
3481 | /** |
||
3482 | * Clear all custom headers. |
||
3483 | */ |
||
3484 | public function clearCustomHeaders() |
||
3488 | |||
3489 | /** |
||
3490 | * Add an error message to the error container. |
||
3491 | * |
||
3492 | * @param string $msg |
||
3493 | */ |
||
3494 | protected function setError($msg) |
||
3514 | |||
3515 | /** |
||
3516 | * Return an RFC 822 formatted date. |
||
3517 | * |
||
3518 | * @return string |
||
3519 | */ |
||
3520 | public static function rfcDate() |
||
3528 | |||
3529 | /** |
||
3530 | * Get the server hostname. |
||
3531 | * Returns 'localhost.localdomain' if unknown. |
||
3532 | * |
||
3533 | * @return string |
||
3534 | */ |
||
3535 | protected function serverHostname() |
||
3553 | |||
3554 | /** |
||
3555 | * Validate whether a string contains a valid value to use as a hostname or IP address. |
||
3556 | * IPv6 addresses must include [], e.g. `[::1]`, not just `::1`. |
||
3557 | * |
||
3558 | * @param string $host The host name or IP address to check |
||
3559 | * |
||
3560 | * @return bool |
||
3561 | */ |
||
3562 | public static function isValidHost($host) |
||
3588 | |||
3589 | /** |
||
3590 | * Get an error message in the current language. |
||
3591 | * |
||
3592 | * @param string $key |
||
3593 | * |
||
3594 | * @return string |
||
3595 | */ |
||
3596 | protected function lang($key) |
||
3616 | |||
3617 | /** |
||
3618 | * Check if an error occurred. |
||
3619 | * |
||
3620 | * @return bool True if an error did occur |
||
3621 | */ |
||
3622 | public function isError() |
||
3626 | |||
3627 | /** |
||
3628 | * Add a custom header. |
||
3629 | * $name value can be overloaded to contain |
||
3630 | * both header name and value (name:value). |
||
3631 | * |
||
3632 | * @param string $name Custom header name |
||
3633 | * @param string|null $value Header value |
||
3634 | */ |
||
3635 | public function addCustomHeader($name, $value = null) |
||
3644 | |||
3645 | /** |
||
3646 | * Returns all custom headers. |
||
3647 | * |
||
3648 | * @return array |
||
3649 | */ |
||
3650 | public function getCustomHeaders() |
||
3654 | |||
3655 | /** |
||
3656 | * Create a message body from an HTML string. |
||
3657 | * Automatically inlines images and creates a plain-text version by converting the HTML, |
||
3658 | * overwriting any existing values in Body and AltBody. |
||
3659 | * Do not source $message content from user input! |
||
3660 | * $basedir is prepended when handling relative URLs, e.g. <img src="/images/a.png"> and must not be empty |
||
3661 | * will look for an image file in $basedir/images/a.png and convert it to inline. |
||
3662 | * If you don't provide a $basedir, relative paths will be left untouched (and thus probably break in email) |
||
3663 | * Converts data-uri images into embedded attachments. |
||
3664 | * If you don't want to apply these transformations to your HTML, just set Body and AltBody directly. |
||
3665 | * |
||
3666 | * @param string $message HTML message string |
||
3667 | * @param string $basedir Absolute path to a base directory to prepend to relative paths to images |
||
3668 | * @param bool|callable $advanced Whether to use the internal HTML to text converter |
||
3669 | * or your own custom converter @see PHPMailer::html2text() |
||
3670 | * |
||
3671 | * @return string $message The transformed message Body |
||
3672 | */ |
||
3673 | public function msgHTML($message, $basedir = '', $advanced = false) |
||
3756 | |||
3757 | /** |
||
3758 | * Convert an HTML string into plain text. |
||
3759 | * This is used by msgHTML(). |
||
3760 | * Note - older versions of this function used a bundled advanced converter |
||
3761 | * which was removed for license reasons in #232. |
||
3762 | * Example usage: |
||
3763 | * |
||
3764 | * ```php |
||
3765 | * // Use default conversion |
||
3766 | * $plain = $mail->html2text($html); |
||
3767 | * // Use your own custom converter |
||
3768 | * $plain = $mail->html2text($html, function($html) { |
||
3769 | * $converter = new MyHtml2text($html); |
||
3770 | * return $converter->get_text(); |
||
3771 | * }); |
||
3772 | * ``` |
||
3773 | * |
||
3774 | * @param string $html The HTML text to convert |
||
3775 | * @param bool|callable $advanced Any boolean value to use the internal converter, |
||
3776 | * or provide your own callable for custom conversion |
||
3777 | * |
||
3778 | * @return string |
||
3779 | */ |
||
3780 | public function html2text($html, $advanced = false) |
||
3792 | |||
3793 | /** |
||
3794 | * Get the MIME type for a file extension. |
||
3795 | * |
||
3796 | * @param string $ext File extension |
||
3797 | * |
||
3798 | * @return string MIME type of file |
||
3799 | */ |
||
3800 | public static function _mime_types($ext = '') |
||
3909 | |||
3910 | /** |
||
3911 | * Map a file name to a MIME type. |
||
3912 | * Defaults to 'application/octet-stream', i.e.. arbitrary binary data. |
||
3913 | * |
||
3914 | * @param string $filename A file name or full path, does not need to exist as a file |
||
3915 | * |
||
3916 | * @return string |
||
3917 | */ |
||
3918 | public static function filenameToType($filename) |
||
3929 | |||
3930 | /** |
||
3931 | * Multi-byte-safe pathinfo replacement. |
||
3932 | * Drop-in replacement for pathinfo(), but multibyte- and cross-platform-safe. |
||
3933 | * |
||
3934 | * @see http://www.php.net/manual/en/function.pathinfo.php#107461 |
||
3935 | * |
||
3936 | * @param string $path A filename or path, does not need to exist as a file |
||
3937 | * @param int|string $options Either a PATHINFO_* constant, |
||
3938 | * or a string name to return only the specified piece |
||
3939 | * |
||
3940 | * @return string|array |
||
3941 | */ |
||
3942 | public static function mb_pathinfo($path, $options = null) |
||
3977 | |||
3978 | /** |
||
3979 | * Set or reset instance properties. |
||
3980 | * You should avoid this function - it's more verbose, less efficient, more error-prone and |
||
3981 | * harder to debug than setting properties directly. |
||
3982 | * Usage Example: |
||
3983 | * `$mail->set('SMTPSecure', 'tls');` |
||
3984 | * is the same as: |
||
3985 | * `$mail->SMTPSecure = 'tls';`. |
||
3986 | * |
||
3987 | * @param string $name The property name to set |
||
3988 | * @param mixed $value The value to set the property to |
||
3989 | * |
||
3990 | * @return bool |
||
3991 | */ |
||
3992 | public function set($name, $value = '') |
||
4003 | |||
4004 | /** |
||
4005 | * Strip newlines to prevent header injection. |
||
4006 | * |
||
4007 | * @param string $str |
||
4008 | * |
||
4009 | * @return string |
||
4010 | */ |
||
4011 | public function secureHeader($str) |
||
4015 | |||
4016 | /** |
||
4017 | * Normalize line breaks in a string. |
||
4018 | * Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format. |
||
4019 | * Defaults to CRLF (for message bodies) and preserves consecutive breaks. |
||
4020 | * |
||
4021 | * @param string $text |
||
4022 | * @param string $breaktype What kind of line break to use; defaults to static::$LE |
||
4023 | * |
||
4024 | * @return string |
||
4025 | */ |
||
4026 | public static function normalizeBreaks($text, $breaktype = null) |
||
4040 | |||
4041 | /** |
||
4042 | * Return the current line break format string. |
||
4043 | * |
||
4044 | * @return string |
||
4045 | */ |
||
4046 | public static function getLE() |
||
4050 | |||
4051 | /** |
||
4052 | * Set the line break format string, e.g. "\r\n". |
||
4053 | * |
||
4054 | * @param string $le |
||
4055 | */ |
||
4056 | protected static function setLE($le) |
||
4060 | |||
4061 | /** |
||
4062 | * Set the public and private key files and password for S/MIME signing. |
||
4063 | * |
||
4064 | * @param string $cert_filename |
||
4065 | * @param string $key_filename |
||
4066 | * @param string $key_pass Password for private key |
||
4067 | * @param string $extracerts_filename Optional path to chain certificate |
||
4068 | */ |
||
4069 | public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename = '') |
||
4076 | |||
4077 | /** |
||
4078 | * Quoted-Printable-encode a DKIM header. |
||
4079 | * |
||
4080 | * @param string $txt |
||
4081 | * |
||
4082 | * @return string |
||
4083 | */ |
||
4084 | public function DKIM_QP($txt) |
||
4099 | |||
4100 | /** |
||
4101 | * Generate a DKIM signature. |
||
4102 | * |
||
4103 | * @param string $signHeader |
||
4104 | * |
||
4105 | * @throws Exception |
||
4106 | * |
||
4107 | * @return string The DKIM signature value |
||
4108 | */ |
||
4109 | public function DKIM_Sign($signHeader) |
||
4135 | |||
4136 | /** |
||
4137 | * Generate a DKIM canonicalization header. |
||
4138 | * Uses the 'relaxed' algorithm from RFC6376 section 3.4.2. |
||
4139 | * |
||
4140 | * @see https://tools.ietf.org/html/rfc6376#section-3.4.2 |
||
4141 | * |
||
4142 | * @param string $signHeader Header |
||
4143 | * |
||
4144 | * @return string |
||
4145 | */ |
||
4146 | public function DKIM_HeaderC($signHeader) |
||
4176 | |||
4177 | /** |
||
4178 | * Generate a DKIM canonicalization body. |
||
4179 | * Uses the 'simple' algorithm from RFC6376 section 3.4.3. |
||
4180 | * |
||
4181 | * @see https://tools.ietf.org/html/rfc6376#section-3.4.3 |
||
4182 | * |
||
4183 | * @param string $body Message Body |
||
4184 | * |
||
4185 | * @return string |
||
4186 | */ |
||
4187 | public function DKIM_BodyC($body) |
||
4198 | |||
4199 | /** |
||
4200 | * Create the DKIM header and body in a new message header. |
||
4201 | * |
||
4202 | * @param string $headers_line Header lines |
||
4203 | * @param string $subject Subject |
||
4204 | * @param string $body Body |
||
4205 | * |
||
4206 | * @return string |
||
4207 | */ |
||
4208 | public function DKIM_Add($headers_line, $subject, $body) |
||
4280 | |||
4281 | /** |
||
4282 | * Detect if a string contains a line longer than the maximum line length |
||
4283 | * allowed by RFC 2822 section 2.1.1. |
||
4284 | * |
||
4285 | * @param string $str |
||
4286 | * |
||
4287 | * @return bool |
||
4288 | */ |
||
4289 | public static function hasLineLongerThanMax($str) |
||
4293 | |||
4294 | /** |
||
4295 | * Allows for public read access to 'to' property. |
||
4296 | * Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
||
4297 | * |
||
4298 | * @return array |
||
4299 | */ |
||
4300 | public function getToAddresses() |
||
4304 | |||
4305 | /** |
||
4306 | * Allows for public read access to 'cc' property. |
||
4307 | * Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
||
4308 | * |
||
4309 | * @return array |
||
4310 | */ |
||
4311 | public function getCcAddresses() |
||
4315 | |||
4316 | /** |
||
4317 | * Allows for public read access to 'bcc' property. |
||
4318 | * Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
||
4319 | * |
||
4320 | * @return array |
||
4321 | */ |
||
4322 | public function getBccAddresses() |
||
4326 | |||
4327 | /** |
||
4328 | * Allows for public read access to 'ReplyTo' property. |
||
4329 | * Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
||
4330 | * |
||
4331 | * @return array |
||
4332 | */ |
||
4333 | public function getReplyToAddresses() |
||
4337 | |||
4338 | /** |
||
4339 | * Allows for public read access to 'all_recipients' property. |
||
4340 | * Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
||
4341 | * |
||
4342 | * @return array |
||
4343 | */ |
||
4344 | public function getAllRecipientAddresses() |
||
4348 | |||
4349 | /** |
||
4350 | * Perform a callback. |
||
4351 | * |
||
4352 | * @param bool $isSent |
||
4353 | * @param array $to |
||
4354 | * @param array $cc |
||
4355 | * @param array $bcc |
||
4356 | * @param string $subject |
||
4357 | * @param string $body |
||
4358 | * @param string $from |
||
4359 | * @param array $extra |
||
4360 | */ |
||
4361 | protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from, $extra) |
||
4367 | |||
4368 | /** |
||
4369 | * Get the OAuth instance. |
||
4370 | * |
||
4371 | * @return OAuth |
||
4372 | */ |
||
4373 | public function getOAuth() |
||
4377 | |||
4378 | /** |
||
4379 | * Set an OAuth instance. |
||
4380 | * |
||
4381 | * @param OAuth $oauth |
||
4382 | */ |
||
4383 | public function setOAuth(OAuth $oauth) |
||
4387 | } |
||
4388 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.