| @@ -3,9 +3,8 @@ | ||
| 3 | 3 | namespace BitCode\BitForm\Core\Util; |
| 4 | 4 | |
| 5 | 5 | use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 6 | 6 | |
| 7 | - | |
| 8 | 7 | /** |
| 9 | 8 | * Class handling plugin activation. |
| 10 | 9 | * |
| 11 | 10 | * @since 1.0.0 |
| @@ -11,32 +10,40 @@ | ||
| 11 | 10 | * @since 1.0.0 |
| 12 | 11 | */ |
| 13 | 12 | final class MailConfig |
| 14 | 13 | { |
| 15 | - public function sendMail() | |
| 16 | - { | |
| 17 | - add_action('phpmailer_init', [$this, 'mailConfig'], 10, 1); | |
| 18 | - } | |
| 19 | - function mailConfig($phpmailer) | |
| 20 | - { | |
| 21 | - $integrationHandler = new IntegrationHandler(0); | |
| 22 | - $formIntegrations = $integrationHandler->getAllIntegration('mail', 'smtp', 1); | |
| 23 | - if (!isset($formIntegrations->errors['result_empty'])) { | |
| 24 | - if ($formIntegrations[0]->status == 1) { | |
| 25 | - $integration_details = json_decode($formIntegrations[0]->integration_details); | |
| 26 | - $phpmailer->Mailer = 'smtp'; | |
| 27 | - $phpmailer->Host = $integration_details->smtp_host; | |
| 28 | - $phpmailer->SMTPAuth = true; | |
| 29 | - if(!empty($integration_details->re_email_address)){ | |
| 30 | - $phpmailer->addReplyTo($integration_details->re_email_address,'reply-to'); | |
| 31 | - } | |
| 32 | - $phpmailer->Port = $integration_details->port; | |
| 33 | - $phpmailer->Username = $integration_details->smtp_user_name; | |
| 34 | - $phpmailer->Password = $integration_details->smtp_password; | |
| 35 | - $phpmailer->SMTPSecure = $integration_details->encryption; | |
| 36 | - $phpmailer->SMTP_DEBUG = 1; | |
| 37 | - $phpmailer->From = $integration_details->form_email_address; | |
| 38 | - $phpmailer->FromName = $integration_details->form_name; | |
| 39 | - } | |
| 14 | + private $config; | |
| 15 | + | |
| 16 | + public function sendMail($config = []) | |
| 17 | + { | |
| 18 | + $this->config = $config; | |
| 19 | + add_action('phpmailer_init', [$this, 'mailConfig'], 10, 1); | |
| 20 | + } | |
| 21 | + | |
| 22 | + public function mailConfig($phpmailer) | |
| 23 | + { | |
| 24 | + $integrationHandler = new IntegrationHandler(0); | |
| 25 | + $formIntegrations = $integrationHandler->getAllIntegration('mail', 'smtp', 1); | |
| 26 | + if (!isset($formIntegrations->errors['result_empty'])) { | |
| 27 | + if (1 === (int) $formIntegrations[0]->status) { | |
| 28 | + $integration_details = json_decode($formIntegrations[0]->integration_details); | |
| 29 | + $phpmailer->Mailer = 'smtp'; | |
| 30 | + $phpmailer->Host = $integration_details->smtp_host; | |
| 31 | + $phpmailer->SMTPAuth = true; | |
| 32 | + if (!empty($integration_details->re_email_address)) { | |
| 33 | + $phpmailer->addReplyTo($integration_details->re_email_address, 'reply-to'); | |
| 40 | 34 | } |
| 35 | + $phpmailer->Port = $integration_details->port; | |
| 36 | + $phpmailer->Username = $integration_details->smtp_user_name; | |
| 37 | + $phpmailer->Password = $integration_details->smtp_password; | |
| 38 | + $phpmailer->SMTPSecure = $integration_details->encryption; | |
| 39 | + $phpmailer->SMTP_DEBUG = 1; | |
| 40 | + $phpmailer->From = $integration_details->form_email_address; | |
| 41 | + $from_name = $integration_details->form_name; | |
| 42 | + if (isset($this->config['from_name']) && !empty($this->config['from_name'])) { | |
| 43 | + $from_name = $this->config['from_name']; | |
| 44 | + } | |
| 45 | + $phpmailer->FromName = $from_name; | |
| 46 | + } | |
| 41 | 47 | } |
| 48 | + } | |
| 42 | 49 | } |