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; |
||
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; |
||
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; |
||
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.5'; |
||
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 | * This length does NOT include the line break |
||
712 | * 76 means that lines will be 77 or 78 chars depending on whether |
||
713 | * the line break format is LF or CRLF; both are valid. |
||
714 | * |
||
715 | * @var int |
||
716 | */ |
||
717 | const STD_LINE_LENGTH = 76; |
||
718 | |||
719 | /** |
||
720 | * Constructor. |
||
721 | * |
||
722 | * @param bool $exceptions Should we throw external exceptions? |
||
|
|||
723 | */ |
||
724 | public function __construct($exceptions = null) |
||
732 | |||
733 | /** |
||
734 | * Destructor. |
||
735 | */ |
||
736 | public function __destruct() |
||
741 | |||
742 | /** |
||
743 | * Call mail() in a safe_mode-aware fashion. |
||
744 | * Also, unless sendmail_path points to sendmail (or something that |
||
745 | * claims to be sendmail), don't pass params (not a perfect fix, |
||
746 | * but it will do). |
||
747 | * |
||
748 | * @param string $to To |
||
749 | * @param string $subject Subject |
||
750 | * @param string $body Message Body |
||
751 | * @param string $header Additional Header(s) |
||
752 | * @param string|null $params Params |
||
753 | * |
||
754 | * @return bool |
||
755 | */ |
||
756 | private function mailPassthru($to, $subject, $body, $header, $params) |
||
773 | |||
774 | /** |
||
775 | * Output debugging info via user-defined method. |
||
776 | * Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug). |
||
777 | * |
||
778 | * @see PHPMailer::$Debugoutput |
||
779 | * @see PHPMailer::$SMTPDebug |
||
780 | * |
||
781 | * @param string $str |
||
782 | */ |
||
783 | protected function edebug($str) |
||
831 | |||
832 | /** |
||
833 | * Sets message type to HTML or plain. |
||
834 | * |
||
835 | * @param bool $isHtml True for HTML mode |
||
836 | */ |
||
837 | public function isHTML($isHtml = true) |
||
845 | |||
846 | /** |
||
847 | * Send messages using SMTP. |
||
848 | */ |
||
849 | public function isSMTP() |
||
853 | |||
854 | /** |
||
855 | * Send messages using PHP's mail() function. |
||
856 | */ |
||
857 | public function isMail() |
||
861 | |||
862 | /** |
||
863 | * Send messages using $Sendmail. |
||
864 | */ |
||
865 | View Code Duplication | public function isSendmail() |
|
876 | |||
877 | /** |
||
878 | * Send messages using qmail. |
||
879 | */ |
||
880 | View Code Duplication | public function isQmail() |
|
891 | |||
892 | /** |
||
893 | * Add a "To" address. |
||
894 | * |
||
895 | * @param string $address The email address to send to |
||
896 | * @param string $name |
||
897 | * |
||
898 | * @return bool true on success, false if address already used or invalid in some way |
||
899 | */ |
||
900 | public function addAddress($address, $name = '') |
||
904 | |||
905 | /** |
||
906 | * Add a "CC" address. |
||
907 | * |
||
908 | * @param string $address The email address to send to |
||
909 | * @param string $name |
||
910 | * |
||
911 | * @return bool true on success, false if address already used or invalid in some way |
||
912 | */ |
||
913 | public function addCC($address, $name = '') |
||
917 | |||
918 | /** |
||
919 | * Add a "BCC" address. |
||
920 | * |
||
921 | * @param string $address The email address to send to |
||
922 | * @param string $name |
||
923 | * |
||
924 | * @return bool true on success, false if address already used or invalid in some way |
||
925 | */ |
||
926 | public function addBCC($address, $name = '') |
||
930 | |||
931 | /** |
||
932 | * Add a "Reply-To" address. |
||
933 | * |
||
934 | * @param string $address The email address to reply to |
||
935 | * @param string $name |
||
936 | * |
||
937 | * @return bool true on success, false if address already used or invalid in some way |
||
938 | */ |
||
939 | public function addReplyTo($address, $name = '') |
||
943 | |||
944 | /** |
||
945 | * Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer |
||
946 | * can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still |
||
947 | * be modified after calling this function), addition of such addresses is delayed until send(). |
||
948 | * Addresses that have been added already return false, but do not throw exceptions. |
||
949 | * |
||
950 | * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo' |
||
951 | * @param string $address The email address to send, resp. to reply to |
||
952 | * @param string $name |
||
953 | * |
||
954 | * @throws Exception |
||
955 | * |
||
956 | * @return bool true on success, false if address already used or invalid in some way |
||
957 | */ |
||
958 | protected function addOrEnqueueAnAddress($kind, $address, $name) |
||
1000 | |||
1001 | /** |
||
1002 | * Add an address to one of the recipient arrays or to the ReplyTo array. |
||
1003 | * Addresses that have been added already return false, but do not throw exceptions. |
||
1004 | * |
||
1005 | * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo' |
||
1006 | * @param string $address The email address to send, resp. to reply to |
||
1007 | * @param string $name |
||
1008 | * |
||
1009 | * @throws Exception |
||
1010 | * |
||
1011 | * @return bool true on success, false if address already used or invalid in some way |
||
1012 | */ |
||
1013 | protected function addAnAddress($kind, $address, $name = '') |
||
1057 | |||
1058 | /** |
||
1059 | * Parse and validate a string containing one or more RFC822-style comma-separated email addresses |
||
1060 | * of the form "display name <address>" into an array of name/address pairs. |
||
1061 | * Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. |
||
1062 | * Note that quotes in the name part are removed. |
||
1063 | * |
||
1064 | * @see http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation |
||
1065 | * |
||
1066 | * @param string $addrstr The address list string |
||
1067 | * @param bool $useimap Whether to use the IMAP extension to parse the list |
||
1068 | * |
||
1069 | * @return array |
||
1070 | */ |
||
1071 | public static function parseAddresses($addrstr, $useimap = true) |
||
1116 | |||
1117 | /** |
||
1118 | * Set the From and FromName properties. |
||
1119 | * |
||
1120 | * @param string $address |
||
1121 | * @param string $name |
||
1122 | * @param bool $auto Whether to also set the Sender address, defaults to true |
||
1123 | * |
||
1124 | * @throws Exception |
||
1125 | * |
||
1126 | * @return bool |
||
1127 | */ |
||
1128 | public function setFrom($address, $name = '', $auto = true) |
||
1158 | |||
1159 | /** |
||
1160 | * Return the Message-ID header of the last email. |
||
1161 | * Technically this is the value from the last time the headers were created, |
||
1162 | * but it's also the message ID of the last sent message except in |
||
1163 | * pathological cases. |
||
1164 | * |
||
1165 | * @return string |
||
1166 | */ |
||
1167 | public function getLastMessageID() |
||
1171 | |||
1172 | /** |
||
1173 | * Check that a string looks like an email address. |
||
1174 | * Validation patterns supported: |
||
1175 | * * `auto` Pick best pattern automatically; |
||
1176 | * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0; |
||
1177 | * * `pcre` Use old PCRE implementation; |
||
1178 | * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; |
||
1179 | * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements. |
||
1180 | * * `noregex` Don't use a regex: super fast, really dumb. |
||
1181 | * Alternatively you may pass in a callable to inject your own validator, for example: |
||
1182 | * |
||
1183 | * ```php |
||
1184 | * PHPMailer::validateAddress('[email protected]', function($address) { |
||
1185 | * return (strpos($address, '@') !== false); |
||
1186 | * }); |
||
1187 | * ``` |
||
1188 | * |
||
1189 | * You can also set the PHPMailer::$validator static to a callable, allowing built-in methods to use your validator. |
||
1190 | * |
||
1191 | * @param string $address The email address to check |
||
1192 | * @param string|callable $patternselect Which pattern to use |
||
1193 | * |
||
1194 | * @return bool |
||
1195 | */ |
||
1196 | public static function validateAddress($address, $patternselect = null) |
||
1255 | |||
1256 | /** |
||
1257 | * Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the |
||
1258 | * `intl` and `mbstring` PHP extensions. |
||
1259 | * |
||
1260 | * @return bool `true` if required functions for IDN support are present |
||
1261 | */ |
||
1262 | public static function idnSupported() |
||
1266 | |||
1267 | /** |
||
1268 | * Converts IDN in given email address to its ASCII form, also known as punycode, if possible. |
||
1269 | * Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet. |
||
1270 | * This function silently returns unmodified address if: |
||
1271 | * - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form) |
||
1272 | * - Conversion to punycode is impossible (e.g. required PHP functions are not available) |
||
1273 | * or fails for any reason (e.g. domain contains characters not allowed in an IDN). |
||
1274 | * |
||
1275 | * @see PHPMailer::$CharSet |
||
1276 | * |
||
1277 | * @param string $address The email address to convert |
||
1278 | * |
||
1279 | * @return string The encoded address in ASCII form |
||
1280 | */ |
||
1281 | public function punyencodeAddress($address) |
||
1304 | |||
1305 | /** |
||
1306 | * Create a message and send it. |
||
1307 | * Uses the sending method specified by $Mailer. |
||
1308 | * |
||
1309 | * @throws Exception |
||
1310 | * |
||
1311 | * @return bool false on error - See the ErrorInfo property for details of the error |
||
1312 | */ |
||
1313 | public function send() |
||
1331 | |||
1332 | /** |
||
1333 | * Prepare a message for sending. |
||
1334 | * |
||
1335 | * @throws Exception |
||
1336 | * |
||
1337 | * @return bool |
||
1338 | */ |
||
1339 | public function preSend() |
||
1464 | |||
1465 | /** |
||
1466 | * Actually send a message via the selected mechanism. |
||
1467 | * |
||
1468 | * @throws Exception |
||
1469 | * |
||
1470 | * @return bool |
||
1471 | */ |
||
1472 | public function postSend() |
||
1502 | |||
1503 | /** |
||
1504 | * Send mail using the $Sendmail program. |
||
1505 | * |
||
1506 | * @see PHPMailer::$Sendmail |
||
1507 | * |
||
1508 | * @param string $header The message headers |
||
1509 | * @param string $body The message body |
||
1510 | * |
||
1511 | * @throws Exception |
||
1512 | * |
||
1513 | * @return bool |
||
1514 | */ |
||
1515 | protected function sendmailSend($header, $body) |
||
1583 | |||
1584 | /** |
||
1585 | * Fix CVE-2016-10033 and CVE-2016-10045 by disallowing potentially unsafe shell characters. |
||
1586 | * Note that escapeshellarg and escapeshellcmd are inadequate for our purposes, especially on Windows. |
||
1587 | * |
||
1588 | * @see https://github.com/PHPMailer/PHPMailer/issues/924 CVE-2016-10045 bug report |
||
1589 | * |
||
1590 | * @param string $string The string to be validated |
||
1591 | * |
||
1592 | * @return bool |
||
1593 | */ |
||
1594 | protected static function isShellSafe($string) |
||
1618 | |||
1619 | /** |
||
1620 | * Send mail using the PHP mail() function. |
||
1621 | * |
||
1622 | * @see http://www.php.net/manual/en/book.mail.php |
||
1623 | * |
||
1624 | * @param string $header The message headers |
||
1625 | * @param string $body The message body |
||
1626 | * |
||
1627 | * @throws Exception |
||
1628 | * |
||
1629 | * @return bool |
||
1630 | */ |
||
1631 | protected function mailSend($header, $body) |
||
1676 | |||
1677 | /** |
||
1678 | * Get an instance to use for SMTP operations. |
||
1679 | * Override this function to load your own SMTP implementation, |
||
1680 | * or set one with setSMTPInstance. |
||
1681 | * |
||
1682 | * @return SMTP |
||
1683 | */ |
||
1684 | public function getSMTPInstance() |
||
1692 | |||
1693 | /** |
||
1694 | * Provide an instance to use for SMTP operations. |
||
1695 | * |
||
1696 | * @param SMTP $smtp |
||
1697 | * |
||
1698 | * @return SMTP |
||
1699 | */ |
||
1700 | public function setSMTPInstance(SMTP $smtp) |
||
1706 | |||
1707 | /** |
||
1708 | * Send mail via SMTP. |
||
1709 | * Returns false if there is a bad MAIL FROM, RCPT, or DATA input. |
||
1710 | * |
||
1711 | * @see PHPMailer::setSMTPInstance() to use a different class. |
||
1712 | * |
||
1713 | * @uses \PHPMailer\PHPMailer\SMTP |
||
1714 | * |
||
1715 | * @param string $header The message headers |
||
1716 | * @param string $body The message body |
||
1717 | * |
||
1718 | * @throws Exception |
||
1719 | * |
||
1720 | * @return bool |
||
1721 | */ |
||
1722 | protected function smtpSend($header, $body) |
||
1796 | |||
1797 | /** |
||
1798 | * Initiate a connection to an SMTP server. |
||
1799 | * Returns false if the operation failed. |
||
1800 | * |
||
1801 | * @param array $options An array of options compatible with stream_context_create() |
||
1802 | * |
||
1803 | * @throws Exception |
||
1804 | * |
||
1805 | * @uses \PHPMailer\PHPMailer\SMTP |
||
1806 | * |
||
1807 | * @return bool |
||
1808 | */ |
||
1809 | public function smtpConnect($options = null) |
||
1933 | |||
1934 | /** |
||
1935 | * Close the active SMTP session if one exists. |
||
1936 | */ |
||
1937 | public function smtpClose() |
||
1946 | |||
1947 | /** |
||
1948 | * Set the language for error messages. |
||
1949 | * Returns false if it cannot load the language file. |
||
1950 | * The default language is English. |
||
1951 | * |
||
1952 | * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr") |
||
1953 | * @param string $lang_path Path to the language file directory, with trailing separator (slash) |
||
1954 | * |
||
1955 | * @return bool |
||
1956 | */ |
||
1957 | public function setLanguage($langcode = 'en', $lang_path = '') |
||
2020 | |||
2021 | /** |
||
2022 | * Get the array of strings for the current language. |
||
2023 | * |
||
2024 | * @return array |
||
2025 | */ |
||
2026 | public function getTranslations() |
||
2030 | |||
2031 | /** |
||
2032 | * Create recipient headers. |
||
2033 | * |
||
2034 | * @param string $type |
||
2035 | * @param array $addr An array of recipients, |
||
2036 | * where each recipient is a 2-element indexed array with element 0 containing an address |
||
2037 | * and element 1 containing a name, like: |
||
2038 | * [['[email protected]', 'Joe User'], ['[email protected]', 'Zoe User']] |
||
2039 | * |
||
2040 | * @return string |
||
2041 | */ |
||
2042 | public function addrAppend($type, $addr) |
||
2051 | |||
2052 | /** |
||
2053 | * Format an address for use in a message header. |
||
2054 | * |
||
2055 | * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name like |
||
2056 | * ['[email protected]', 'Joe User'] |
||
2057 | * |
||
2058 | * @return string |
||
2059 | */ |
||
2060 | public function addrFormat($addr) |
||
2070 | |||
2071 | /** |
||
2072 | * Word-wrap message. |
||
2073 | * For use with mailers that do not automatically perform wrapping |
||
2074 | * and for quoted-printable encoded messages. |
||
2075 | * Original written by philippe. |
||
2076 | * |
||
2077 | * @param string $message The message to wrap |
||
2078 | * @param int $length The line length to wrap to |
||
2079 | * @param bool $qp_mode Whether to run in Quoted-Printable mode |
||
2080 | * |
||
2081 | * @return string |
||
2082 | */ |
||
2083 | public function wrapText($message, $length, $qp_mode = false) |
||
2172 | |||
2173 | /** |
||
2174 | * Find the last character boundary prior to $maxLength in a utf-8 |
||
2175 | * quoted-printable encoded string. |
||
2176 | * Original written by Colin Brown. |
||
2177 | * |
||
2178 | * @param string $encodedText utf-8 QP text |
||
2179 | * @param int $maxLength Find the last character boundary prior to this length |
||
2180 | * |
||
2181 | * @return int |
||
2182 | */ |
||
2183 | public function utf8CharBoundary($encodedText, $maxLength) |
||
2220 | |||
2221 | /** |
||
2222 | * Apply word wrapping to the message body. |
||
2223 | * Wraps the message body to the number of chars set in the WordWrap property. |
||
2224 | * You should only do this to plain-text bodies as wrapping HTML tags may break them. |
||
2225 | * This is called automatically by createBody(), so you don't need to call it yourself. |
||
2226 | */ |
||
2227 | public function setWordWrap() |
||
2245 | |||
2246 | /** |
||
2247 | * Assemble message headers. |
||
2248 | * |
||
2249 | * @return string The assembled headers |
||
2250 | */ |
||
2251 | public function createHeader() |
||
2340 | |||
2341 | /** |
||
2342 | * Get the message MIME type headers. |
||
2343 | * |
||
2344 | * @return string |
||
2345 | */ |
||
2346 | public function getMailMIME() |
||
2392 | |||
2393 | /** |
||
2394 | * Returns the whole MIME message. |
||
2395 | * Includes complete headers and body. |
||
2396 | * Only valid post preSend(). |
||
2397 | * |
||
2398 | * @see PHPMailer::preSend() |
||
2399 | * |
||
2400 | * @return string |
||
2401 | */ |
||
2402 | public function getSentMIMEMessage() |
||
2406 | |||
2407 | /** |
||
2408 | * Create a unique ID to use for boundaries. |
||
2409 | * |
||
2410 | * @return string |
||
2411 | */ |
||
2412 | protected function generateId() |
||
2427 | |||
2428 | /** |
||
2429 | * Assemble the message body. |
||
2430 | * Returns an empty string on failure. |
||
2431 | * |
||
2432 | * @throws Exception |
||
2433 | * |
||
2434 | * @return string The assembled message body |
||
2435 | */ |
||
2436 | public function createBody() |
||
2647 | |||
2648 | /** |
||
2649 | * Return the start of a message boundary. |
||
2650 | * |
||
2651 | * @param string $boundary |
||
2652 | * @param string $charSet |
||
2653 | * @param string $contentType |
||
2654 | * @param string $encoding |
||
2655 | * |
||
2656 | * @return string |
||
2657 | */ |
||
2658 | protected function getBoundary($boundary, $charSet, $contentType, $encoding) |
||
2681 | |||
2682 | /** |
||
2683 | * Return the end of a message boundary. |
||
2684 | * |
||
2685 | * @param string $boundary |
||
2686 | * |
||
2687 | * @return string |
||
2688 | */ |
||
2689 | protected function endBoundary($boundary) |
||
2693 | |||
2694 | /** |
||
2695 | * Set the message type. |
||
2696 | * PHPMailer only supports some preset message types, not arbitrary MIME structures. |
||
2697 | */ |
||
2698 | protected function setMessageType() |
||
2716 | |||
2717 | /** |
||
2718 | * Format a header line. |
||
2719 | * |
||
2720 | * @param string $name |
||
2721 | * @param string|int $value |
||
2722 | * |
||
2723 | * @return string |
||
2724 | */ |
||
2725 | public function headerLine($name, $value) |
||
2729 | |||
2730 | /** |
||
2731 | * Return a formatted mail line. |
||
2732 | * |
||
2733 | * @param string $value |
||
2734 | * |
||
2735 | * @return string |
||
2736 | */ |
||
2737 | public function textLine($value) |
||
2741 | |||
2742 | /** |
||
2743 | * Add an attachment from a path on the filesystem. |
||
2744 | * Never use a user-supplied path to a file! |
||
2745 | * Returns false if the file could not be found or read. |
||
2746 | * |
||
2747 | * @param string $path Path to the attachment |
||
2748 | * @param string $name Overrides the attachment name |
||
2749 | * @param string $encoding File encoding (see $Encoding) |
||
2750 | * @param string $type File extension (MIME) type |
||
2751 | * @param string $disposition Disposition to use |
||
2752 | * |
||
2753 | * @throws Exception |
||
2754 | * |
||
2755 | * @return bool |
||
2756 | */ |
||
2757 | public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment') |
||
2796 | |||
2797 | /** |
||
2798 | * Return the array of attachments. |
||
2799 | * |
||
2800 | * @return array |
||
2801 | */ |
||
2802 | public function getAttachments() |
||
2806 | |||
2807 | /** |
||
2808 | * Attach all file, string, and binary attachments to the message. |
||
2809 | * Returns an empty string on failure. |
||
2810 | * |
||
2811 | * @param string $disposition_type |
||
2812 | * @param string $boundary |
||
2813 | * |
||
2814 | * @return string |
||
2815 | */ |
||
2816 | protected function attachAll($disposition_type, $boundary) |
||
2927 | |||
2928 | /** |
||
2929 | * Encode a file attachment in requested format. |
||
2930 | * Returns an empty string on failure. |
||
2931 | * |
||
2932 | * @param string $path The full path to the file |
||
2933 | * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' |
||
2934 | * |
||
2935 | * @throws Exception |
||
2936 | * |
||
2937 | * @return string |
||
2938 | */ |
||
2939 | protected function encodeFile($path, $encoding = 'base64') |
||
2958 | |||
2959 | /** |
||
2960 | * Encode a string in requested format. |
||
2961 | * Returns an empty string on failure. |
||
2962 | * |
||
2963 | * @param string $str The text to encode |
||
2964 | * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable |
||
2965 | * |
||
2966 | * @return string |
||
2967 | */ |
||
2968 | public function encodeString($str, $encoding = 'base64') |
||
3000 | |||
3001 | /** |
||
3002 | * Encode a header value (not including its label) optimally. |
||
3003 | * Picks shortest of Q, B, or none. Result includes folding if needed. |
||
3004 | * See RFC822 definitions for phrase, comment and text positions. |
||
3005 | * |
||
3006 | * @param string $str The header value to encode |
||
3007 | * @param string $position What context the string will be used in |
||
3008 | * |
||
3009 | * @return string |
||
3010 | */ |
||
3011 | public function encodeHeader($str, $position = 'text') |
||
3086 | |||
3087 | /** |
||
3088 | * Check if a string contains multi-byte characters. |
||
3089 | * |
||
3090 | * @param string $str multi-byte text to wrap encode |
||
3091 | * |
||
3092 | * @return bool |
||
3093 | */ |
||
3094 | public function hasMultiBytes($str) |
||
3103 | |||
3104 | /** |
||
3105 | * Does a string contain any 8-bit chars (in any charset)? |
||
3106 | * |
||
3107 | * @param string $text |
||
3108 | * |
||
3109 | * @return bool |
||
3110 | */ |
||
3111 | public function has8bitChars($text) |
||
3115 | |||
3116 | /** |
||
3117 | * Encode and wrap long multibyte strings for mail headers |
||
3118 | * without breaking lines within a character. |
||
3119 | * Adapted from a function by paravoid. |
||
3120 | * |
||
3121 | * @see http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283 |
||
3122 | * |
||
3123 | * @param string $str multi-byte text to wrap encode |
||
3124 | * @param string $linebreak string to use as linefeed/end-of-line |
||
3125 | * |
||
3126 | * @return string |
||
3127 | */ |
||
3128 | public function base64EncodeWrapMB($str, $linebreak = null) |
||
3159 | |||
3160 | /** |
||
3161 | * Encode a string in quoted-printable format. |
||
3162 | * According to RFC2045 section 6.7. |
||
3163 | * |
||
3164 | * @param string $string The text to encode |
||
3165 | * |
||
3166 | * @return string |
||
3167 | */ |
||
3168 | public function encodeQP($string) |
||
3172 | |||
3173 | /** |
||
3174 | * Encode a string using Q encoding. |
||
3175 | * |
||
3176 | * @see http://tools.ietf.org/html/rfc2047#section-4.2 |
||
3177 | * |
||
3178 | * @param string $str the text to encode |
||
3179 | * @param string $position Where the text is going to be used, see the RFC for what that means |
||
3180 | * |
||
3181 | * @return string |
||
3182 | */ |
||
3183 | public function encodeQ($str, $position = 'text') |
||
3226 | |||
3227 | /** |
||
3228 | * Add a string or binary attachment (non-filesystem). |
||
3229 | * This method can be used to attach ascii or binary data, |
||
3230 | * such as a BLOB record from a database. |
||
3231 | * |
||
3232 | * @param string $string String attachment data |
||
3233 | * @param string $filename Name of the attachment |
||
3234 | * @param string $encoding File encoding (see $Encoding) |
||
3235 | * @param string $type File extension (MIME) type |
||
3236 | * @param string $disposition Disposition to use |
||
3237 | */ |
||
3238 | public function addStringAttachment( |
||
3261 | |||
3262 | /** |
||
3263 | * Add an embedded (inline) attachment from a file. |
||
3264 | * This can include images, sounds, and just about any other document type. |
||
3265 | * These differ from 'regular' attachments in that they are intended to be |
||
3266 | * displayed inline with the message, not just attached for download. |
||
3267 | * This is used in HTML messages that embed the images |
||
3268 | * the HTML refers to using the $cid value. |
||
3269 | * Never use a user-supplied path to a file! |
||
3270 | * |
||
3271 | * @param string $path Path to the attachment |
||
3272 | * @param string $cid Content ID of the attachment; Use this to reference |
||
3273 | * the content when using an embedded image in HTML |
||
3274 | * @param string $name Overrides the attachment name |
||
3275 | * @param string $encoding File encoding (see $Encoding) |
||
3276 | * @param string $type File MIME type |
||
3277 | * @param string $disposition Disposition to use |
||
3278 | * |
||
3279 | * @return bool True on successfully adding an attachment |
||
3280 | */ |
||
3281 | public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline') |
||
3313 | |||
3314 | /** |
||
3315 | * Add an embedded stringified attachment. |
||
3316 | * This can include images, sounds, and just about any other document type. |
||
3317 | * If your filename doesn't contain an extension, be sure to set the $type to an appropriate MIME type. |
||
3318 | * |
||
3319 | * @param string $string The attachment binary data |
||
3320 | * @param string $cid Content ID of the attachment; Use this to reference |
||
3321 | * the content when using an embedded image in HTML |
||
3322 | * @param string $name A filename for the attachment. If this contains an extension, |
||
3323 | * PHPMailer will attempt to set a MIME type for the attachment. |
||
3324 | * For example 'file.jpg' would get an 'image/jpeg' MIME type. |
||
3325 | * @param string $encoding File encoding (see $Encoding), defaults to 'base64' |
||
3326 | * @param string $type MIME type - will be used in preference to any automatically derived type |
||
3327 | * @param string $disposition Disposition to use |
||
3328 | * |
||
3329 | * @return bool True on successfully adding an attachment |
||
3330 | */ |
||
3331 | public function addStringEmbeddedImage( |
||
3358 | |||
3359 | /** |
||
3360 | * Check if an embedded attachment is present with this cid. |
||
3361 | * |
||
3362 | * @param string $cid |
||
3363 | * |
||
3364 | * @return bool |
||
3365 | */ |
||
3366 | View Code Duplication | protected function cidExists($cid) |
|
3376 | |||
3377 | /** |
||
3378 | * Check if an inline attachment is present. |
||
3379 | * |
||
3380 | * @return bool |
||
3381 | */ |
||
3382 | View Code Duplication | public function inlineImageExists() |
|
3392 | |||
3393 | /** |
||
3394 | * Check if an attachment (non-inline) is present. |
||
3395 | * |
||
3396 | * @return bool |
||
3397 | */ |
||
3398 | public function attachmentExists() |
||
3408 | |||
3409 | /** |
||
3410 | * Check if this message has an alternative body set. |
||
3411 | * |
||
3412 | * @return bool |
||
3413 | */ |
||
3414 | public function alternativeExists() |
||
3418 | |||
3419 | /** |
||
3420 | * Clear queued addresses of given kind. |
||
3421 | * |
||
3422 | * @param string $kind 'to', 'cc', or 'bcc' |
||
3423 | */ |
||
3424 | public function clearQueuedAddresses($kind) |
||
3433 | |||
3434 | /** |
||
3435 | * Clear all To recipients. |
||
3436 | */ |
||
3437 | public function clearAddresses() |
||
3445 | |||
3446 | /** |
||
3447 | * Clear all CC recipients. |
||
3448 | */ |
||
3449 | View Code Duplication | public function clearCCs() |
|
3457 | |||
3458 | /** |
||
3459 | * Clear all BCC recipients. |
||
3460 | */ |
||
3461 | View Code Duplication | public function clearBCCs() |
|
3469 | |||
3470 | /** |
||
3471 | * Clear all ReplyTo recipients. |
||
3472 | */ |
||
3473 | public function clearReplyTos() |
||
3478 | |||
3479 | /** |
||
3480 | * Clear all recipient types. |
||
3481 | */ |
||
3482 | public function clearAllRecipients() |
||
3490 | |||
3491 | /** |
||
3492 | * Clear all filesystem, string, and binary attachments. |
||
3493 | */ |
||
3494 | public function clearAttachments() |
||
3498 | |||
3499 | /** |
||
3500 | * Clear all custom headers. |
||
3501 | */ |
||
3502 | public function clearCustomHeaders() |
||
3506 | |||
3507 | /** |
||
3508 | * Add an error message to the error container. |
||
3509 | * |
||
3510 | * @param string $msg |
||
3511 | */ |
||
3512 | protected function setError($msg) |
||
3532 | |||
3533 | /** |
||
3534 | * Return an RFC 822 formatted date. |
||
3535 | * |
||
3536 | * @return string |
||
3537 | */ |
||
3538 | public static function rfcDate() |
||
3546 | |||
3547 | /** |
||
3548 | * Get the server hostname. |
||
3549 | * Returns 'localhost.localdomain' if unknown. |
||
3550 | * |
||
3551 | * @return string |
||
3552 | */ |
||
3553 | protected function serverHostname() |
||
3571 | |||
3572 | /** |
||
3573 | * Validate whether a string contains a valid value to use as a hostname or IP address. |
||
3574 | * IPv6 addresses must include [], e.g. `[::1]`, not just `::1`. |
||
3575 | * |
||
3576 | * @param string $host The host name or IP address to check |
||
3577 | * |
||
3578 | * @return bool |
||
3579 | */ |
||
3580 | public static function isValidHost($host) |
||
3606 | |||
3607 | /** |
||
3608 | * Get an error message in the current language. |
||
3609 | * |
||
3610 | * @param string $key |
||
3611 | * |
||
3612 | * @return string |
||
3613 | */ |
||
3614 | protected function lang($key) |
||
3634 | |||
3635 | /** |
||
3636 | * Check if an error occurred. |
||
3637 | * |
||
3638 | * @return bool True if an error did occur |
||
3639 | */ |
||
3640 | public function isError() |
||
3644 | |||
3645 | /** |
||
3646 | * Add a custom header. |
||
3647 | * $name value can be overloaded to contain |
||
3648 | * both header name and value (name:value). |
||
3649 | * |
||
3650 | * @param string $name Custom header name |
||
3651 | * @param string|null $value Header value |
||
3652 | */ |
||
3653 | public function addCustomHeader($name, $value = null) |
||
3662 | |||
3663 | /** |
||
3664 | * Returns all custom headers. |
||
3665 | * |
||
3666 | * @return array |
||
3667 | */ |
||
3668 | public function getCustomHeaders() |
||
3672 | |||
3673 | /** |
||
3674 | * Create a message body from an HTML string. |
||
3675 | * Automatically inlines images and creates a plain-text version by converting the HTML, |
||
3676 | * overwriting any existing values in Body and AltBody. |
||
3677 | * Do not source $message content from user input! |
||
3678 | * $basedir is prepended when handling relative URLs, e.g. <img src="/images/a.png"> and must not be empty |
||
3679 | * will look for an image file in $basedir/images/a.png and convert it to inline. |
||
3680 | * If you don't provide a $basedir, relative paths will be left untouched (and thus probably break in email) |
||
3681 | * Converts data-uri images into embedded attachments. |
||
3682 | * If you don't want to apply these transformations to your HTML, just set Body and AltBody directly. |
||
3683 | * |
||
3684 | * @param string $message HTML message string |
||
3685 | * @param string $basedir Absolute path to a base directory to prepend to relative paths to images |
||
3686 | * @param bool|callable $advanced Whether to use the internal HTML to text converter |
||
3687 | * or your own custom converter @see PHPMailer::html2text() |
||
3688 | * |
||
3689 | * @return string $message The transformed message Body |
||
3690 | */ |
||
3691 | public function msgHTML($message, $basedir = '', $advanced = false) |
||
3774 | |||
3775 | /** |
||
3776 | * Convert an HTML string into plain text. |
||
3777 | * This is used by msgHTML(). |
||
3778 | * Note - older versions of this function used a bundled advanced converter |
||
3779 | * which was removed for license reasons in #232. |
||
3780 | * Example usage: |
||
3781 | * |
||
3782 | * ```php |
||
3783 | * // Use default conversion |
||
3784 | * $plain = $mail->html2text($html); |
||
3785 | * // Use your own custom converter |
||
3786 | * $plain = $mail->html2text($html, function($html) { |
||
3787 | * $converter = new MyHtml2text($html); |
||
3788 | * return $converter->get_text(); |
||
3789 | * }); |
||
3790 | * ``` |
||
3791 | * |
||
3792 | * @param string $html The HTML text to convert |
||
3793 | * @param bool|callable $advanced Any boolean value to use the internal converter, |
||
3794 | * or provide your own callable for custom conversion |
||
3795 | * |
||
3796 | * @return string |
||
3797 | */ |
||
3798 | public function html2text($html, $advanced = false) |
||
3810 | |||
3811 | /** |
||
3812 | * Get the MIME type for a file extension. |
||
3813 | * |
||
3814 | * @param string $ext File extension |
||
3815 | * |
||
3816 | * @return string MIME type of file |
||
3817 | */ |
||
3818 | public static function _mime_types($ext = '') |
||
3940 | |||
3941 | /** |
||
3942 | * Map a file name to a MIME type. |
||
3943 | * Defaults to 'application/octet-stream', i.e.. arbitrary binary data. |
||
3944 | * |
||
3945 | * @param string $filename A file name or full path, does not need to exist as a file |
||
3946 | * |
||
3947 | * @return string |
||
3948 | */ |
||
3949 | public static function filenameToType($filename) |
||
3960 | |||
3961 | /** |
||
3962 | * Multi-byte-safe pathinfo replacement. |
||
3963 | * Drop-in replacement for pathinfo(), but multibyte- and cross-platform-safe. |
||
3964 | * |
||
3965 | * @see http://www.php.net/manual/en/function.pathinfo.php#107461 |
||
3966 | * |
||
3967 | * @param string $path A filename or path, does not need to exist as a file |
||
3968 | * @param int|string $options Either a PATHINFO_* constant, |
||
3969 | * or a string name to return only the specified piece |
||
3970 | * |
||
3971 | * @return string|array |
||
3972 | */ |
||
3973 | public static function mb_pathinfo($path, $options = null) |
||
4008 | |||
4009 | /** |
||
4010 | * Set or reset instance properties. |
||
4011 | * You should avoid this function - it's more verbose, less efficient, more error-prone and |
||
4012 | * harder to debug than setting properties directly. |
||
4013 | * Usage Example: |
||
4014 | * `$mail->set('SMTPSecure', 'tls');` |
||
4015 | * is the same as: |
||
4016 | * `$mail->SMTPSecure = 'tls';`. |
||
4017 | * |
||
4018 | * @param string $name The property name to set |
||
4019 | * @param mixed $value The value to set the property to |
||
4020 | * |
||
4021 | * @return bool |
||
4022 | */ |
||
4023 | public function set($name, $value = '') |
||
4034 | |||
4035 | /** |
||
4036 | * Strip newlines to prevent header injection. |
||
4037 | * |
||
4038 | * @param string $str |
||
4039 | * |
||
4040 | * @return string |
||
4041 | */ |
||
4042 | public function secureHeader($str) |
||
4046 | |||
4047 | /** |
||
4048 | * Normalize line breaks in a string. |
||
4049 | * Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format. |
||
4050 | * Defaults to CRLF (for message bodies) and preserves consecutive breaks. |
||
4051 | * |
||
4052 | * @param string $text |
||
4053 | * @param string $breaktype What kind of line break to use; defaults to static::$LE |
||
4054 | * |
||
4055 | * @return string |
||
4056 | */ |
||
4057 | public static function normalizeBreaks($text, $breaktype = null) |
||
4071 | |||
4072 | /** |
||
4073 | * Return the current line break format string. |
||
4074 | * |
||
4075 | * @return string |
||
4076 | */ |
||
4077 | public static function getLE() |
||
4081 | |||
4082 | /** |
||
4083 | * Set the line break format string, e.g. "\r\n". |
||
4084 | * |
||
4085 | * @param string $le |
||
4086 | */ |
||
4087 | protected static function setLE($le) |
||
4091 | |||
4092 | /** |
||
4093 | * Set the public and private key files and password for S/MIME signing. |
||
4094 | * |
||
4095 | * @param string $cert_filename |
||
4096 | * @param string $key_filename |
||
4097 | * @param string $key_pass Password for private key |
||
4098 | * @param string $extracerts_filename Optional path to chain certificate |
||
4099 | */ |
||
4100 | public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename = '') |
||
4107 | |||
4108 | /** |
||
4109 | * Quoted-Printable-encode a DKIM header. |
||
4110 | * |
||
4111 | * @param string $txt |
||
4112 | * |
||
4113 | * @return string |
||
4114 | */ |
||
4115 | public function DKIM_QP($txt) |
||
4130 | |||
4131 | /** |
||
4132 | * Generate a DKIM signature. |
||
4133 | * |
||
4134 | * @param string $signHeader |
||
4135 | * |
||
4136 | * @throws Exception |
||
4137 | * |
||
4138 | * @return string The DKIM signature value |
||
4139 | */ |
||
4140 | public function DKIM_Sign($signHeader) |
||
4166 | |||
4167 | /** |
||
4168 | * Generate a DKIM canonicalization header. |
||
4169 | * Uses the 'relaxed' algorithm from RFC6376 section 3.4.2. |
||
4170 | * Canonicalized headers should *always* use CRLF, regardless of mailer setting. |
||
4171 | * |
||
4172 | * @see https://tools.ietf.org/html/rfc6376#section-3.4.2 |
||
4173 | * |
||
4174 | * @param string $signHeader Header |
||
4175 | * |
||
4176 | * @return string |
||
4177 | */ |
||
4178 | public function DKIM_HeaderC($signHeader) |
||
4208 | |||
4209 | /** |
||
4210 | * Generate a DKIM canonicalization body. |
||
4211 | * Uses the 'simple' algorithm from RFC6376 section 3.4.3. |
||
4212 | * Canonicalized bodies should *always* use CRLF, regardless of mailer setting. |
||
4213 | * |
||
4214 | * @see https://tools.ietf.org/html/rfc6376#section-3.4.3 |
||
4215 | * |
||
4216 | * @param string $body Message Body |
||
4217 | * |
||
4218 | * @return string |
||
4219 | */ |
||
4220 | public function DKIM_BodyC($body) |
||
4231 | |||
4232 | /** |
||
4233 | * Create the DKIM header and body in a new message header. |
||
4234 | * |
||
4235 | * @param string $headers_line Header lines |
||
4236 | * @param string $subject Subject |
||
4237 | * @param string $body Body |
||
4238 | * |
||
4239 | * @return string |
||
4240 | */ |
||
4241 | public function DKIM_Add($headers_line, $subject, $body) |
||
4313 | |||
4314 | /** |
||
4315 | * Detect if a string contains a line longer than the maximum line length |
||
4316 | * allowed by RFC 2822 section 2.1.1. |
||
4317 | * |
||
4318 | * @param string $str |
||
4319 | * |
||
4320 | * @return bool |
||
4321 | */ |
||
4322 | public static function hasLineLongerThanMax($str) |
||
4326 | |||
4327 | /** |
||
4328 | * Allows for public read access to 'to' property. |
||
4329 | * Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
||
4330 | * |
||
4331 | * @return array |
||
4332 | */ |
||
4333 | public function getToAddresses() |
||
4337 | |||
4338 | /** |
||
4339 | * Allows for public read access to 'cc' property. |
||
4340 | * Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
||
4341 | * |
||
4342 | * @return array |
||
4343 | */ |
||
4344 | public function getCcAddresses() |
||
4348 | |||
4349 | /** |
||
4350 | * Allows for public read access to 'bcc' property. |
||
4351 | * Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
||
4352 | * |
||
4353 | * @return array |
||
4354 | */ |
||
4355 | public function getBccAddresses() |
||
4359 | |||
4360 | /** |
||
4361 | * Allows for public read access to 'ReplyTo' property. |
||
4362 | * Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
||
4363 | * |
||
4364 | * @return array |
||
4365 | */ |
||
4366 | public function getReplyToAddresses() |
||
4370 | |||
4371 | /** |
||
4372 | * Allows for public read access to 'all_recipients' property. |
||
4373 | * Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
||
4374 | * |
||
4375 | * @return array |
||
4376 | */ |
||
4377 | public function getAllRecipientAddresses() |
||
4381 | |||
4382 | /** |
||
4383 | * Perform a callback. |
||
4384 | * |
||
4385 | * @param bool $isSent |
||
4386 | * @param array $to |
||
4387 | * @param array $cc |
||
4388 | * @param array $bcc |
||
4389 | * @param string $subject |
||
4390 | * @param string $body |
||
4391 | * @param string $from |
||
4392 | * @param array $extra |
||
4393 | */ |
||
4394 | protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from, $extra) |
||
4400 | |||
4401 | /** |
||
4402 | * Get the OAuth instance. |
||
4403 | * |
||
4404 | * @return OAuth |
||
4405 | */ |
||
4406 | public function getOAuth() |
||
4410 | |||
4411 | /** |
||
4412 | * Set an OAuth instance. |
||
4413 | * |
||
4414 | * @param OAuth $oauth |
||
4415 | */ |
||
4416 | public function setOAuth(OAuth $oauth) |
||
4420 | } |
||
4421 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.