public function send($to, $subject, $message, $data = array()) { $send_method = $this->get_send_method($this->get_db_settings_option('method')); if (!$send_method) { return array('status' => 0, 'message' => __('Invalid send method', 'fw')); } if (is_wp_error($send_method_configuration = $send_method->prepare_settings_options_values($this->get_db_settings_option($send_method->get_id())))) { return array('status' => 0, 'message' => $send_method_configuration->get_error_message()); } $email = new FW_Ext_Mailer_Email(); $email->set_to($to); $email->set_subject($subject); $email->set_body($message); $result = $send_method->send($email, $this->get_db_settings_option($send_method->get_id()), $data); return is_wp_error($result) ? array('status' => 0, 'message' => $result->get_error_message()) : array('status' => 1, 'message' => __('The message has been successfully sent!', 'fw')); }
/** * @param array $settings_options_values * @param FW_Ext_Mailer_Email $email * @param array $data * @return bool|WP_Error */ public function send(FW_Ext_Mailer_Email $email, $settings_options_values, $data = array()) { if (!class_exists('PHPMailer')) { require_once ABSPATH . WPINC . '/class-phpmailer.php'; } $config = self::prepare_settings_options_values($settings_options_values); if (is_wp_error($config)) { return $config; } $mailer = new PHPMailer(); $mailer->isSMTP(); $mailer->IsHTML(true); $mailer->Host = $config['host']; $mailer->Port = $config['port']; $mailer->SMTPSecure = $config['secure']; $mailer->SMTPAuth = true; $mailer->Username = $config['username']; $mailer->Password = $config['password']; $mailer->CharSet = 'utf-8'; $mailer->From = $email->get_from(); $mailer->FromName = $email->get_from_name(); if (is_array($email->get_to())) { foreach ($email->get_to() as $to_address) { $mailer->AddAddress($to_address); } } else { $mailer->AddAddress($email->get_to()); } $mailer->Subject = $email->get_subject(); $mailer->Body = $email->get_body(); //$mailer->SMTPDebug = true; $result = $mailer->send(); $mailer->ClearAddresses(); $mailer->ClearAllRecipients(); unset($mailer); return $result ? true : new WP_Error('failed', __('Could not send the email', 'fw')); }
/** * @param array $settings_options_values * @param FW_Ext_Mailer_Email $email * @param array $data * @return bool|WP_Error */ public function send(FW_Ext_Mailer_Email $email, $settings_options_values, $data = array()) { $result = wp_mail($email->get_to(), $email->get_subject(), $email->get_body(), array('Content-type: text/html; charset=utf-8', 'From:' . htmlspecialchars($email->get_from_name(), null, 'UTF-8') . ' <' . htmlspecialchars($email->get_from(), null, 'UTF-8') . '>')); return $result ? true : new WP_Error('failed', __('Could not send the email', 'fw')); }