PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.4.5
EmailKit – Email Customizer for WooCommerce & WP v1.4.5
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
emailkit / includes / Admin / Api / TestEmail.php

TestEmail.php in EmailKit – Email Customizer for WooCommerce & WP 1.4.5, at includes/Admin/Api/TestEmail.php

63 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EmailKit\Admin\Api;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class TestEmail {
8
9 public $prefix = '';
10 public $param = '';
11 public $request = null;
12 public function __construct() {
13
14 add_action('rest_api_init', function () {
15 register_rest_route('emailkit/v1', 'send-test-email', array(
16 'methods' => \WP_REST_Server::ALLMETHODS,
17 'callback' => [$this, 'sendEmail'],
18 'permission_callback' => '__return_true',
19 ));
20 });
21 }
22
23 public function sendEmail($request)
24 {
25 if (!wp_verify_nonce($request->get_header('X-WP-Nonce'), 'wp_rest')) {
26 return [
27 'status' => 'fail',
28 'message' => [esc_html__('Nonce mismatch.', 'emailkit')]
29 ];
30 }
31
32 if (!is_user_logged_in() || !current_user_can('publish_posts')) {
33 return [
34 'status' => 'fail',
35 'message' => [ esc_html__('Access denied.', 'emailkit')]
36 ];
37 }
38
39 $from = get_option('admin_email');
40 $to = $request->get_param('email');
41 $subject = $request->get_param('subject');
42 $message = $request->get_param('message');
43 $headers = [
44 'From: ' . $from . "\r\n",
45 'Reply-To: ' . $from . "\r\n",
46 'Content-Type: text/html; charset=UTF-8',
47 ];
48
49 $sent = wp_mail($to, $subject, $message, $headers);
50
51 if ($sent) {
52 return [
53 'status' => 'success',
54 'message' => [ esc_html__('Test email sent successfully.', 'emailkit')],
55 ];
56 } else {
57 return [
58 'status' => 'fail',
59 'message' => [ esc_html__('Failed to send the test email.', 'emailkit') ],
60 ];
61 }
62 }
63 }