| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * @package VikWP - Libraries |
| 4 | 4 | * @subpackage adapter.mail |
| 5 | 5 | * @author E4J s.r.l. |
| 6 | - * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. | |
| 6 | + * @copyright Copyright (C) 2023 E4J s.r.l. All Rights Reserved. | |
| 7 | 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | 8 | * @link https://vikwp.com |
| 9 | 9 | */ |
| 10 | 10 | |
| @@ -99,32 +99,41 @@ | ||
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | 101 | * Magic method set to define certain object properties. |
| 102 | 102 | * |
| 103 | - * @param string $name the property name | |
| 104 | - * @param mixed $value the value for the property | |
| 103 | + * @param string $name The property name. | |
| 104 | + * @param mixed $value The value for the property. | |
| 105 | 105 | * |
| 106 | - * @return void | |
| 106 | + * @return void | |
| 107 | 107 | * |
| 108 | - * @since 10.1.6 | |
| 108 | + * @since 10.1.6 | |
| 109 | 109 | */ |
| 110 | 110 | public function __set($name, $value) |
| 111 | 111 | { |
| 112 | - if (strcasecmp($name, 'SMTPOptions')) | |
| 113 | - { | |
| 114 | - return; | |
| 115 | - } | |
| 116 | - | |
| 117 | 112 | // hook to the PHPMailer init action |
| 118 | - add_action('phpmailer_init', function(&$phpmailer) use ($value) | |
| 113 | + add_action('phpmailer_init', function(&$phpmailer) use ($name, $value) | |
| 119 | 114 | { |
| 120 | - if (!$phpmailer instanceof PHPMailer) | |
| 115 | + /** | |
| 116 | + * Make sure the provided argument is actually an object. | |
| 117 | + * | |
| 118 | + * @since 10.1.61 Ignore the PHPMailer class check, since it might be prefixed by a namespace. | |
| 119 | + * Receiving an object is enough for us. | |
| 120 | + */ | |
| 121 | + if (!is_object($phpmailer)) | |
| 121 | 122 | { |
| 122 | 123 | // safety check |
| 123 | - return $phpmailer; | |
| 124 | + return; | |
| 124 | 125 | } |
| 125 | 126 | |
| 126 | - $phpmailer->SMTPOptions = $value; | |
| 127 | + /** | |
| 128 | + * Check whether the specified property is supported by PHPMailer. | |
| 129 | + * | |
| 130 | + * @since 10.1.47 | |
| 131 | + */ | |
| 132 | + if (property_exists($phpmailer, $name)) | |
| 133 | + { | |
| 134 | + $phpmailer->{$name} = $value; | |
| 135 | + } | |
| 127 | 136 | }); |
| 128 | 137 | } |
| 129 | 138 | |
| 130 | 139 | /** |
| @@ -408,18 +417,24 @@ | ||
| 408 | 417 | { |
| 409 | 418 | // hook to the PHPMailer init action |
| 410 | 419 | add_action('phpmailer_init', function(&$phpmailer) use ($auth, $host, $user, $pass, $secure, $port) |
| 411 | 420 | { |
| 412 | - if (!$phpmailer instanceof PHPMailer) | |
| 421 | + /** | |
| 422 | + * Make sure the provided argument is actually an object. | |
| 423 | + * | |
| 424 | + * @since 10.1.62 Ignore the PHPMailer class check, since it might be prefixed by a namespace. | |
| 425 | + * Receiving an object is enough for us. | |
| 426 | + */ | |
| 427 | + if (!is_object($phpmailer)) | |
| 413 | 428 | { |
| 414 | 429 | // safety check |
| 415 | - return $phpmailer; | |
| 430 | + return; | |
| 416 | 431 | } |
| 417 | 432 | |
| 418 | 433 | if ($auth === null || $host === null || $user === null || $pass === null) |
| 419 | 434 | { |
| 420 | 435 | // do not interfere if the plugin parameters are null |
| 421 | - return $phpmailer; | |
| 436 | + return; | |
| 422 | 437 | } |
| 423 | 438 | |
| 424 | 439 | // Tell PHPMailer to use SMTP |
| 425 | 440 | $phpmailer->isSMTP(); |
| @@ -441,13 +456,13 @@ | ||
| 441 | 456 | |
| 442 | 457 | if ($secure == 'ssl' || $secure == 'tls') |
| 443 | 458 | { |
| 444 | 459 | $phpmailer->SMTPSecure = $secure; |
| 445 | - } else { | |
| 460 | + } | |
| 461 | + else | |
| 462 | + { | |
| 446 | 463 | $phpmailer->SMTPAutoTLS = false; |
| 447 | 464 | } |
| 448 | - | |
| 449 | - return $phpmailer; | |
| 450 | 465 | }); |
| 451 | 466 | |
| 452 | 467 | return true; |
| 453 | 468 | } |