From 1f5470e677bc92440e72c95038b7230835626eba Mon Sep 17 00:00:00 2001 From: abuyoyo Date: Sun, 3 Nov 2024 23:52:40 +0200 Subject: [PATCH 01/13] CHANGELOG.md --- CHANGELOG.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d3200ba --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,29 @@ +# Changelog + +All notable changes to Send WP Mail plugin. + +## [1.0](https://plugins.svn.wordpress.org/send-email-from-admin/tags/1.0/) +- Fix typos. + +## [0.9.3](https://plugins.svn.wordpress.org/send-email-from-admin/tags/0.9.3/) +- Add links. +- Minor css changes. + +## [0.9.2](https://plugins.svn.wordpress.org/send-email-from-admin/tags/0.9.2/) +- Minor code cleanup +- Add HTML5 'required' attribute to form fields. +- Only load js and css on admin page. + +## [0.9.1](https://plugins.svn.wordpress.org/send-email-from-admin/tags/0.9.1/) +- Cleanup css and html. +- Add mail dashicon to title. +- Uploaded file (attachment) is now deleted from server after email is sent. + +## [0.9](https://plugins.svn.wordpress.org/send-email-from-admin/tags/0.9/) +### Initial release +- Send email from admin page. +- Send email to multiple recipients. +- Send individual emails to multiple recipients. +- Add images from the WordPress Media Library. +- Upload and attach one attachment to the email message. +- Select recipients from registered users' email addresses. From 36e735ae5a479786dae6e45ed1222a81dc6d3970 Mon Sep 17 00:00:00 2001 From: abuyoyo Date: Sun, 3 Nov 2024 23:12:22 +0200 Subject: [PATCH 02/13] Rename files send-wp-mail --- css/{sefa.css => send-wp-mail.css} | 176 +++--- js/{sefa.js => send-wp-mail.js} | 0 send-email-from-admin.php => send-wp-mail.php | 534 +++++++++--------- 3 files changed, 355 insertions(+), 355 deletions(-) rename css/{sefa.css => send-wp-mail.css} (94%) rename js/{sefa.js => send-wp-mail.js} (100%) rename send-email-from-admin.php => send-wp-mail.php (96%) diff --git a/css/sefa.css b/css/send-wp-mail.css similarity index 94% rename from css/sefa.css rename to css/send-wp-mail.css index 618ec88..a1844df 100644 --- a/css/sefa.css +++ b/css/send-wp-mail.css @@ -1,89 +1,89 @@ -#sefa-wrapper h1 { - font-size: 2.8em; - font-weight: 200; - margin-bottom: 26px; - margin-left: -4px; -} -#sefa-wrapper h1:before { - font-family: "dashicons"; - content: "\f465"; - top: 8px; - position: relative; - margin-right: 10px; - font-size: 1.2em; -} -#sefa-wrapper div.error ul li { - list-style: initial; - margin-left: 20px; - margin-bottom: 0; -} -#sefa-wrapper div.updated { - padding: 10px; - margin-bottom: 5px; -} -#sefa-form .form-table { - margin-top: 0; -} -#sefa-form .form-table tr:first-child th { - padding-top: 5px; -} -#sefa-form .form-table tr:first-child td { - padding-top: 0; -} -#sefa-form .form-table th { - width: auto; - min-width: 100px; -} -#sefa-form .form-table td { - vertical-align: text-top; -} -#sefa-form .form-table tr:last-child td { - padding: 0 10px; -} -#sefa-form input[type=text], -#sefa-form input[type=email], -#sefa-form textarea, -#sefa-form .wp-editor-wrap { - width: 100%; - padding: 6px 10px -} -#sefa-form .sefa-radio-wrap { - display: inline; -} -#sefa-form .wp-editor-wrap { - padding-left: 0; -} -#sefa-form #sefa-user-list { - margin-top: 7px; -} -#sefa-form .note { - font-size: 12px; - color: #888; - padding: 5px 0 0 1px; -} - -@media screen and (max-width: 1300px) { - #sefa-wrapper { - width: 100%; - margin-left: 0; - } -} -@media screen and (max-width: 900px) { - #sefa-form .sefa-radio-wrap { - display: block; - } -} -@media screen and (max-width: 850px) { - #sefa-wrapper .postbox { - margin-right: 10px; - } -} -@media screen and (max-width: 500px) { - #sefa-wrapper h1 { - font-size: 2em; - margin-left: 0; - } - #sefa-wrapper h1:before { - top: 6px; - } +#sefa-wrapper h1 { + font-size: 2.8em; + font-weight: 200; + margin-bottom: 26px; + margin-left: -4px; +} +#sefa-wrapper h1:before { + font-family: "dashicons"; + content: "\f465"; + top: 8px; + position: relative; + margin-right: 10px; + font-size: 1.2em; +} +#sefa-wrapper div.error ul li { + list-style: initial; + margin-left: 20px; + margin-bottom: 0; +} +#sefa-wrapper div.updated { + padding: 10px; + margin-bottom: 5px; +} +#sefa-form .form-table { + margin-top: 0; +} +#sefa-form .form-table tr:first-child th { + padding-top: 5px; +} +#sefa-form .form-table tr:first-child td { + padding-top: 0; +} +#sefa-form .form-table th { + width: auto; + min-width: 100px; +} +#sefa-form .form-table td { + vertical-align: text-top; +} +#sefa-form .form-table tr:last-child td { + padding: 0 10px; +} +#sefa-form input[type=text], +#sefa-form input[type=email], +#sefa-form textarea, +#sefa-form .wp-editor-wrap { + width: 100%; + padding: 6px 10px +} +#sefa-form .sefa-radio-wrap { + display: inline; +} +#sefa-form .wp-editor-wrap { + padding-left: 0; +} +#sefa-form #sefa-user-list { + margin-top: 7px; +} +#sefa-form .note { + font-size: 12px; + color: #888; + padding: 5px 0 0 1px; +} + +@media screen and (max-width: 1300px) { + #sefa-wrapper { + width: 100%; + margin-left: 0; + } +} +@media screen and (max-width: 900px) { + #sefa-form .sefa-radio-wrap { + display: block; + } +} +@media screen and (max-width: 850px) { + #sefa-wrapper .postbox { + margin-right: 10px; + } +} +@media screen and (max-width: 500px) { + #sefa-wrapper h1 { + font-size: 2em; + margin-left: 0; + } + #sefa-wrapper h1:before { + top: 6px; + } } \ No newline at end of file diff --git a/js/sefa.js b/js/send-wp-mail.js similarity index 100% rename from js/sefa.js rename to js/send-wp-mail.js diff --git a/send-email-from-admin.php b/send-wp-mail.php similarity index 96% rename from send-email-from-admin.php rename to send-wp-mail.php index 6bcd3ce..313d08a 100644 --- a/send-email-from-admin.php +++ b/send-wp-mail.php @@ -1,268 +1,268 @@ - Send Email. -Version: 1.0 -Author: kojak711 -Domain Path: /languages -Text Domain: sefa - -Send Email From Admin is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Send Email From Admin is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Send Email From Admin. If not, see . -*/ - - -# Exit if accessed directly -if ( ! defined( 'ABSPATH' ) ) { - exit; -} - -define( 'SEFA_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) ); -define( 'SEFA_PLUGIN_VER', '0.9.3' ); - -/** - * Add our sub menu in the Tools menu - * - * @since 0.9.2 - */ -function sefa_plugin_add_admin_page() { - // create sefa submenu page under the Tools menu - $sefa_page = add_submenu_page( 'tools.php', 'Send Email From Admin', 'Send Email', 'manage_options', 'sefa_email', 'sefa_plugin_main' ); - // load js and css on sefa page only - add_action( 'load-' . $sefa_page, 'sefa_plugin_scripts' ); -} -add_action( 'admin_menu', 'sefa_plugin_add_admin_page' ); - -/** - * Load our css and js. - * - * @since 0.9.2 - */ -function sefa_plugin_scripts() { - wp_enqueue_style( 'sefa_admin_css', SEFA_PLUGIN_DIR_URL . 'css/sefa.css', '', SEFA_PLUGIN_VER ); - wp_enqueue_script( 'sefa_admin_js', SEFA_PLUGIN_DIR_URL . 'js/sefa.js', array('jquery'), SEFA_PLUGIN_VER); -} - -/** - * Register our text domain. - * - * @since 0.9 - */ -function sefa_plugin_load_textdomain() { - load_plugin_textdomain( 'sefa', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); -} -add_action('plugins_loaded', 'sefa_plugin_load_textdomain'); - -/** - * Our main function to display and process our form - * - * @since 0.9 - */ -function sefa_plugin_main() { - // get site info to construct 'FROM' for email - $from_name = wp_specialchars_decode( get_option('blogname'), ENT_QUOTES ); - $from_email = get_bloginfo('admin_email'); - - // initialize - $send_mail_message = false; - - if ( !empty( $_POST ) && check_admin_referer( 'sefa_send_email', 'sefa-form-nonce' ) ) { - // handle attachment - $attachment_path = ''; - if ( $_FILES ) { - if ( !function_exists( 'wp_handle_upload' ) ) { - require_once( ABSPATH . 'wp-admin/includes/file.php' ); - } - $uploaded_file = $_FILES['attachment']; - $upload_overrides = array( 'test_form' => false ); - $attachment = wp_handle_upload( $uploaded_file, $upload_overrides ); - if ( $attachment && !isset( $attachment['error'] ) ) { - // file was successfully uploaded - $attachment_path = $attachment['file']; - } else { - // echo $attachment['error']; - } - } - - // get the posted form values - $sefa_recipient_emails = isset( $_POST['sefa_recipient_emails'] ) ? trim($_POST['sefa_recipient_emails']) : ''; - $sefa_subject = isset( $_POST['sefa_subject'] ) ? stripslashes(trim($_POST['sefa_subject'])) : ''; - $sefa_body = isset( $_POST['sefa_body'] ) ? stripslashes(nl2br($_POST['sefa_body'])) : ''; - $sefa_group_email = isset( $_POST['sefa_group_email'] ) ? trim($_POST['sefa_group_email']) : 'no'; - $recipients = explode( ',',$sefa_recipient_emails ); - - // initialize some vars - $errors = array(); - $valid_email = true; - - // simple form validation - if ( empty( $sefa_recipient_emails ) ) { - $errors[] = __( "Please enter an email recipient in the To: field.", 'sefa' ); - } else { - // Loop through each email and validate it - foreach( $recipients as $recipient ) { - if ( !filter_var( trim($recipient), FILTER_VALIDATE_EMAIL ) ) { - $valid_email = false; - break; - } - } - // create appropriate error msg - if ( !$valid_email ) { - $errors[] = _n( "The To: email address appears to be invalid.", "One of the To: email addresses appears to be invalid.", count($recipients), 'sefa' ); - } - } - if ( empty($sefa_subject) ) $errors[] = __( "Please enter a Subject.", 'sefa' ); - if ( empty($sefa_body) ) $errors[] = __( "Please enter a Message.", 'sefa' ); - - // send the email if no errors were found - if ( empty($errors) ) { - $headers[] = "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n"; - $headers[] = 'From: ' . $from_name . ' <' . $from_email . ">\r\n"; - $attachments = $attachment_path; - - if ( $sefa_group_email === 'yes' ) { - if ( wp_mail( $sefa_recipient_emails, $sefa_subject, $sefa_body, $headers, $attachments ) ) { - $send_mail_message = '
' . __( 'Your email has been successfully sent!', 'sefa' ) . '
'; - } else { - $send_mail_message = '
' . __( 'There was an error sending the email.', 'sefa' ) . '
'; - } - } else { - foreach( $recipients as $recipient ) { - if ( wp_mail( $recipient, $sefa_subject, $sefa_body, $headers, $attachments ) ) { - $send_mail_message .= '
' . __( 'Your email has been successfully sent to ', 'sefa' ) . esc_html($recipient) . '!
'; - } else { - $send_mail_message .= '
' . __( 'There was an error sending the email to ', 'sefa' ) . esc_html($recipient) . '
'; - } - } - } - - // delete the uploaded file (attachment) from the server - if ( $attachment_path ) { - unlink($attachment_path); - } - } - } - ?> -
-

-
    '; - foreach ($errors as $error) { - echo "
  • $error
  • "; - } - echo "
\n"; - } - if ( $send_mail_message ) { - echo $send_mail_message; - } - ?> -
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
From:" required>
General.', 'sefa' ); ?>
- -
-
- required> - -
-    -
- required> - -
-
- "200" ); - wp_editor( sefa_plugin_issetor($sefa_body), "sefa_body", $settings ); - ?> -
- -
-
-
-
-
-

Like this plugin?

- -
-
-
-
-
- - Send Email. +Version: 1.0 +Author: kojak711 +Domain Path: /languages +Text Domain: sefa + +Send Email From Admin is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Send Email From Admin is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Send Email From Admin. If not, see . +*/ + + +# Exit if accessed directly +if ( ! defined( 'ABSPATH' ) ) { + exit; +} + +define( 'SEFA_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) ); +define( 'SEFA_PLUGIN_VER', '0.9.3' ); + +/** + * Add our sub menu in the Tools menu + * + * @since 0.9.2 + */ +function sefa_plugin_add_admin_page() { + // create sefa submenu page under the Tools menu + $sefa_page = add_submenu_page( 'tools.php', 'Send Email From Admin', 'Send Email', 'manage_options', 'sefa_email', 'sefa_plugin_main' ); + // load js and css on sefa page only + add_action( 'load-' . $sefa_page, 'sefa_plugin_scripts' ); +} +add_action( 'admin_menu', 'sefa_plugin_add_admin_page' ); + +/** + * Load our css and js. + * + * @since 0.9.2 + */ +function sefa_plugin_scripts() { + wp_enqueue_style( 'sefa_admin_css', SEFA_PLUGIN_DIR_URL . 'css/send-wp-mail.css', '', SEFA_PLUGIN_VER ); + wp_enqueue_script( 'sefa_admin_js', SEFA_PLUGIN_DIR_URL . 'js/send-wp-mail.js', array('jquery'), SEFA_PLUGIN_VER); +} + +/** + * Register our text domain. + * + * @since 0.9 + */ +function sefa_plugin_load_textdomain() { + load_plugin_textdomain( 'sefa', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); +} +add_action('plugins_loaded', 'sefa_plugin_load_textdomain'); + +/** + * Our main function to display and process our form + * + * @since 0.9 + */ +function sefa_plugin_main() { + // get site info to construct 'FROM' for email + $from_name = wp_specialchars_decode( get_option('blogname'), ENT_QUOTES ); + $from_email = get_bloginfo('admin_email'); + + // initialize + $send_mail_message = false; + + if ( !empty( $_POST ) && check_admin_referer( 'sefa_send_email', 'sefa-form-nonce' ) ) { + // handle attachment + $attachment_path = ''; + if ( $_FILES ) { + if ( !function_exists( 'wp_handle_upload' ) ) { + require_once( ABSPATH . 'wp-admin/includes/file.php' ); + } + $uploaded_file = $_FILES['attachment']; + $upload_overrides = array( 'test_form' => false ); + $attachment = wp_handle_upload( $uploaded_file, $upload_overrides ); + if ( $attachment && !isset( $attachment['error'] ) ) { + // file was successfully uploaded + $attachment_path = $attachment['file']; + } else { + // echo $attachment['error']; + } + } + + // get the posted form values + $sefa_recipient_emails = isset( $_POST['sefa_recipient_emails'] ) ? trim($_POST['sefa_recipient_emails']) : ''; + $sefa_subject = isset( $_POST['sefa_subject'] ) ? stripslashes(trim($_POST['sefa_subject'])) : ''; + $sefa_body = isset( $_POST['sefa_body'] ) ? stripslashes(nl2br($_POST['sefa_body'])) : ''; + $sefa_group_email = isset( $_POST['sefa_group_email'] ) ? trim($_POST['sefa_group_email']) : 'no'; + $recipients = explode( ',',$sefa_recipient_emails ); + + // initialize some vars + $errors = array(); + $valid_email = true; + + // simple form validation + if ( empty( $sefa_recipient_emails ) ) { + $errors[] = __( "Please enter an email recipient in the To: field.", 'sefa' ); + } else { + // Loop through each email and validate it + foreach( $recipients as $recipient ) { + if ( !filter_var( trim($recipient), FILTER_VALIDATE_EMAIL ) ) { + $valid_email = false; + break; + } + } + // create appropriate error msg + if ( !$valid_email ) { + $errors[] = _n( "The To: email address appears to be invalid.", "One of the To: email addresses appears to be invalid.", count($recipients), 'sefa' ); + } + } + if ( empty($sefa_subject) ) $errors[] = __( "Please enter a Subject.", 'sefa' ); + if ( empty($sefa_body) ) $errors[] = __( "Please enter a Message.", 'sefa' ); + + // send the email if no errors were found + if ( empty($errors) ) { + $headers[] = "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n"; + $headers[] = 'From: ' . $from_name . ' <' . $from_email . ">\r\n"; + $attachments = $attachment_path; + + if ( $sefa_group_email === 'yes' ) { + if ( wp_mail( $sefa_recipient_emails, $sefa_subject, $sefa_body, $headers, $attachments ) ) { + $send_mail_message = '
' . __( 'Your email has been successfully sent!', 'sefa' ) . '
'; + } else { + $send_mail_message = '
' . __( 'There was an error sending the email.', 'sefa' ) . '
'; + } + } else { + foreach( $recipients as $recipient ) { + if ( wp_mail( $recipient, $sefa_subject, $sefa_body, $headers, $attachments ) ) { + $send_mail_message .= '
' . __( 'Your email has been successfully sent to ', 'sefa' ) . esc_html($recipient) . '!
'; + } else { + $send_mail_message .= '
' . __( 'There was an error sending the email to ', 'sefa' ) . esc_html($recipient) . '
'; + } + } + } + + // delete the uploaded file (attachment) from the server + if ( $attachment_path ) { + unlink($attachment_path); + } + } + } + ?> +
+

+
    '; + foreach ($errors as $error) { + echo "
  • $error
  • "; + } + echo "
\n"; + } + if ( $send_mail_message ) { + echo $send_mail_message; + } + ?> +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
From:" required>
General.', 'sefa' ); ?>
+ +
+
+ required> + +
+    +
+ required> + +
+
+ "200" ); + wp_editor( sefa_plugin_issetor($sefa_body), "sefa_body", $settings ); + ?> +
+ +
+
+
+
+
+

Like this plugin?

+ +
+
+
+
+
+ + Date: Sat, 4 Jan 2025 09:03:08 +0200 Subject: [PATCH 03/13] Rename plugin: Send WP Mail + namespace --- css/send-wp-mail.css | 46 +++++++------- js/send-wp-mail.js | 4 +- send-wp-mail.php | 139 ++++++++++++++++++++----------------------- 3 files changed, 88 insertions(+), 101 deletions(-) diff --git a/css/send-wp-mail.css b/css/send-wp-mail.css index a1844df..7835921 100644 --- a/css/send-wp-mail.css +++ b/css/send-wp-mail.css @@ -1,10 +1,10 @@ -#sefa-wrapper h1 { +#swpm-wrapper h1 { font-size: 2.8em; font-weight: 200; margin-bottom: 26px; margin-left: -4px; } -#sefa-wrapper h1:before { +#swpm-wrapper h1:before { font-family: "dashicons"; content: "\f465"; top: 8px; @@ -12,78 +12,78 @@ margin-right: 10px; font-size: 1.2em; } -#sefa-wrapper div.error ul li { +#swpm-wrapper div.error ul li { list-style: initial; margin-left: 20px; margin-bottom: 0; } -#sefa-wrapper div.updated { +#swpm-wrapper div.updated { padding: 10px; margin-bottom: 5px; } -#sefa-form .form-table { +#swpm-form .form-table { margin-top: 0; } -#sefa-form .form-table tr:first-child th { +#swpm-form .form-table tr:first-child th { padding-top: 5px; } -#sefa-form .form-table tr:first-child td { +#swpm-form .form-table tr:first-child td { padding-top: 0; } -#sefa-form .form-table th { +#swpm-form .form-table th { width: auto; min-width: 100px; } -#sefa-form .form-table td { +#swpm-form .form-table td { vertical-align: text-top; } -#sefa-form .form-table tr:last-child td { +#swpm-form .form-table tr:last-child td { padding: 0 10px; } -#sefa-form input[type=text], -#sefa-form input[type=email], -#sefa-form textarea, -#sefa-form .wp-editor-wrap { +#swpm-form input[type=text], +#swpm-form input[type=email], +#swpm-form textarea, +#swpm-form .wp-editor-wrap { width: 100%; padding: 6px 10px } -#sefa-form .sefa-radio-wrap { +#swpm-form .swpm-radio-wrap { display: inline; } -#sefa-form .wp-editor-wrap { +#swpm-form .wp-editor-wrap { padding-left: 0; } -#sefa-form #sefa-user-list { +#swpm-form #swpm-user-list { margin-top: 7px; } -#sefa-form .note { +#swpm-form .note { font-size: 12px; color: #888; padding: 5px 0 0 1px; } @media screen and (max-width: 1300px) { - #sefa-wrapper { + #swpm-wrapper { width: 100%; margin-left: 0; } } @media screen and (max-width: 900px) { - #sefa-form .sefa-radio-wrap { + #swpm-form .swpm-radio-wrap { display: block; } } @media screen and (max-width: 850px) { - #sefa-wrapper .postbox { + #swpm-wrapper .postbox { margin-right: 10px; } } @media screen and (max-width: 500px) { - #sefa-wrapper h1 { + #swpm-wrapper h1 { font-size: 2em; margin-left: 0; } - #sefa-wrapper h1:before { + #swpm-wrapper h1:before { top: 6px; } } \ No newline at end of file diff --git a/js/send-wp-mail.js b/js/send-wp-mail.js index e585bf2..c174191 100644 --- a/js/send-wp-mail.js +++ b/js/send-wp-mail.js @@ -1,6 +1,6 @@ jQuery( document ).ready( function( $ ) { - $("#sefa-user-list").change( function() { - $recipients = $("#sefa-recipient-emails"); + $("#swpm-user-list").change( function() { + $recipients = $("#swpm-recipient-emails"); if ( $recipients.val() == '' ) { $recipients.val( $(this).find("option:selected").attr("value") ); } else if ( $(this).val() != '' ) { diff --git a/send-wp-mail.php b/send-wp-mail.php index 313d08a..86c8c5a 100644 --- a/send-wp-mail.php +++ b/send-wp-mail.php @@ -1,26 +1,13 @@ Send Email. -Version: 1.0 -Author: kojak711 -Domain Path: /languages -Text Domain: sefa - -Send Email From Admin is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Send Email From Admin is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Send Email From Admin. If not, see . -*/ +/** + * Plugin Name: Send WP Mail + * Update URI: false + * Description: Send email from WordPress. Sends email using WordPress core wp_mail function - if enabled. + * Version: 1.1 + * Author: abuyoyo + * Domain Path: /languages + * Text Domain: swpm + */ # Exit if accessed directly @@ -28,30 +15,30 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -define( 'SEFA_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) ); -define( 'SEFA_PLUGIN_VER', '0.9.3' ); +define( 'SWPM_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) ); +define( 'SWPM_PLUGIN_VER', '0.9.3' ); /** * Add our sub menu in the Tools menu * * @since 0.9.2 */ -function sefa_plugin_add_admin_page() { - // create sefa submenu page under the Tools menu - $sefa_page = add_submenu_page( 'tools.php', 'Send Email From Admin', 'Send Email', 'manage_options', 'sefa_email', 'sefa_plugin_main' ); - // load js and css on sefa page only - add_action( 'load-' . $sefa_page, 'sefa_plugin_scripts' ); +function swpm_plugin_add_admin_page() { + // create swpm submenu page under the Tools menu + $swpm_page = add_submenu_page( 'tools.php', 'Send WP Mail', 'Send Email', 'manage_options', 'send-wp-mail', 'swpm_plugin_main' ); + // load js and css on swpm page only + add_action( 'load-' . $swpm_page, 'swpm_plugin_scripts' ); } -add_action( 'admin_menu', 'sefa_plugin_add_admin_page' ); +add_action( 'admin_menu', 'swpm_plugin_add_admin_page' ); /** * Load our css and js. * * @since 0.9.2 */ -function sefa_plugin_scripts() { - wp_enqueue_style( 'sefa_admin_css', SEFA_PLUGIN_DIR_URL . 'css/send-wp-mail.css', '', SEFA_PLUGIN_VER ); - wp_enqueue_script( 'sefa_admin_js', SEFA_PLUGIN_DIR_URL . 'js/send-wp-mail.js', array('jquery'), SEFA_PLUGIN_VER); +function swpm_plugin_scripts() { + wp_enqueue_style( 'swpm_admin_css', SWPM_PLUGIN_DIR_URL . 'css/send-wp-mail.css', '', SWPM_PLUGIN_VER ); + wp_enqueue_script( 'swpm_admin_js', SWPM_PLUGIN_DIR_URL . 'js/send-wp-mail.js', array('jquery'), SWPM_PLUGIN_VER); } /** @@ -59,17 +46,17 @@ function sefa_plugin_scripts() { * * @since 0.9 */ -function sefa_plugin_load_textdomain() { - load_plugin_textdomain( 'sefa', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); +function swpm_plugin_load_textdomain() { + load_plugin_textdomain( 'swpm', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); } -add_action('plugins_loaded', 'sefa_plugin_load_textdomain'); +add_action('plugins_loaded', 'swpm_plugin_load_textdomain'); /** * Our main function to display and process our form * * @since 0.9 */ -function sefa_plugin_main() { +function swpm_plugin_main() { // get site info to construct 'FROM' for email $from_name = wp_specialchars_decode( get_option('blogname'), ENT_QUOTES ); $from_email = get_bloginfo('admin_email'); @@ -77,7 +64,7 @@ function sefa_plugin_main() { // initialize $send_mail_message = false; - if ( !empty( $_POST ) && check_admin_referer( 'sefa_send_email', 'sefa-form-nonce' ) ) { + if ( !empty( $_POST ) && check_admin_referer( 'send-wp-mail', 'send-wp-mail' ) ) { // handle attachment $attachment_path = ''; if ( $_FILES ) { @@ -96,19 +83,19 @@ function sefa_plugin_main() { } // get the posted form values - $sefa_recipient_emails = isset( $_POST['sefa_recipient_emails'] ) ? trim($_POST['sefa_recipient_emails']) : ''; - $sefa_subject = isset( $_POST['sefa_subject'] ) ? stripslashes(trim($_POST['sefa_subject'])) : ''; - $sefa_body = isset( $_POST['sefa_body'] ) ? stripslashes(nl2br($_POST['sefa_body'])) : ''; - $sefa_group_email = isset( $_POST['sefa_group_email'] ) ? trim($_POST['sefa_group_email']) : 'no'; - $recipients = explode( ',',$sefa_recipient_emails ); + $email_to = isset( $_POST['email_to'] ) ? trim($_POST['email_to']) : ''; + $email_subject = isset( $_POST['email_subject'] ) ? stripslashes(trim($_POST['email_subject'])) : ''; + $email_body = isset( $_POST['email_body'] ) ? stripslashes(nl2br($_POST['email_body'])) : ''; + $group_email = isset( $_POST['group_email'] ) ? trim($_POST['group_email']) : 'no'; + $recipients = explode( ',',$email_to ); // initialize some vars $errors = array(); $valid_email = true; // simple form validation - if ( empty( $sefa_recipient_emails ) ) { - $errors[] = __( "Please enter an email recipient in the To: field.", 'sefa' ); + if ( empty( $email_to ) ) { + $errors[] = __( "Please enter an email recipient in the To: field.", 'swpm' ); } else { // Loop through each email and validate it foreach( $recipients as $recipient ) { @@ -119,11 +106,11 @@ function sefa_plugin_main() { } // create appropriate error msg if ( !$valid_email ) { - $errors[] = _n( "The To: email address appears to be invalid.", "One of the To: email addresses appears to be invalid.", count($recipients), 'sefa' ); + $errors[] = _n( "The To: email address appears to be invalid.", "One of the To: email addresses appears to be invalid.", count($recipients), 'swpm' ); } } - if ( empty($sefa_subject) ) $errors[] = __( "Please enter a Subject.", 'sefa' ); - if ( empty($sefa_body) ) $errors[] = __( "Please enter a Message.", 'sefa' ); + if ( empty($email_subject) ) $errors[] = __( "Please enter a Subject.", 'swpm' ); + if ( empty($email_body) ) $errors[] = __( "Please enter a Message.", 'swpm' ); // send the email if no errors were found if ( empty($errors) ) { @@ -131,18 +118,18 @@ function sefa_plugin_main() { $headers[] = 'From: ' . $from_name . ' <' . $from_email . ">\r\n"; $attachments = $attachment_path; - if ( $sefa_group_email === 'yes' ) { - if ( wp_mail( $sefa_recipient_emails, $sefa_subject, $sefa_body, $headers, $attachments ) ) { - $send_mail_message = '
' . __( 'Your email has been successfully sent!', 'sefa' ) . '
'; + if ( $group_email === 'yes' ) { + if ( wp_mail( $email_to, $email_subject, $email_body, $headers, $attachments ) ) { + $send_mail_message = '
' . __( 'Your email has been successfully sent!', 'swpm' ) . '
'; } else { - $send_mail_message = '
' . __( 'There was an error sending the email.', 'sefa' ) . '
'; + $send_mail_message = '
' . __( 'There was an error sending the email.', 'swpm' ) . '
'; } } else { foreach( $recipients as $recipient ) { - if ( wp_mail( $recipient, $sefa_subject, $sefa_body, $headers, $attachments ) ) { - $send_mail_message .= '
' . __( 'Your email has been successfully sent to ', 'sefa' ) . esc_html($recipient) . '!
'; + if ( wp_mail( $recipient, $email_subject, $email_body, $headers, $attachments ) ) { + $send_mail_message .= '
' . __( 'Your email has been successfully sent to ', 'swpm' ) . esc_html($recipient) . '!
'; } else { - $send_mail_message .= '
' . __( 'There was an error sending the email to ', 'sefa' ) . esc_html($recipient) . '
'; + $send_mail_message .= '
' . __( 'There was an error sending the email to ', 'swpm' ) . esc_html($recipient) . '
'; } } } @@ -154,8 +141,8 @@ function sefa_plugin_main() { } } ?> -
-

+
+

    '; @@ -171,18 +158,18 @@ function sefa_plugin_main() {
    -
    - + + - + - - + - - + + - + @@ -230,7 +217,7 @@ function sefa_plugin_main() {
    From:" required>
    General.', 'sefa' ); ?>
    " required>
    General.', 'swpm' ); ?>
    -
    +
    -
    - required> - +
    + required> +
       -
    - required> - +
    + required> +
    "200" ); - wp_editor( sefa_plugin_issetor($sefa_body), "sefa_body", $settings ); + wp_editor( swpm_plugin_issetor($email_body), "email_body", $settings ); ?>
    - +
    @@ -263,6 +250,6 @@ function sefa_plugin_main() { * * @return string $var value if isset or '' */ -function sefa_plugin_issetor(&$var) { +function swpm_plugin_issetor(&$var) { return isset($var) ? $var : ''; } \ No newline at end of file From 232a901b0c36d08d95ff672cbdcb9bbe2856cecb Mon Sep 17 00:00:00 2001 From: abuyoyo Date: Sat, 4 Jan 2025 09:03:41 +0200 Subject: [PATCH 04/13] Remove localization + readme.txt files --- languages/sefa-fr_FR.mo | Bin 1879 -> 0 bytes languages/sefa-fr_FR.po | 74 ---------------------------------------- languages/sefa.pot | 72 -------------------------------------- readme.txt | 66 ----------------------------------- 4 files changed, 212 deletions(-) delete mode 100644 languages/sefa-fr_FR.mo delete mode 100644 languages/sefa-fr_FR.po delete mode 100644 languages/sefa.pot delete mode 100644 readme.txt diff --git a/languages/sefa-fr_FR.mo b/languages/sefa-fr_FR.mo deleted file mode 100644 index 88c32ce24ad423fde5fa957101b93ba9c5d46eae..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1879 zcma)6&u<$=6ds_ZV169ZLxtcl5kCTm-PnyHB8MWiAuSP!u&}9si#6VTwx^n%+0GBA z=E6U~fdkw*Vvsm1*j z1^fs22Jq#l7<(3Y19*(Lhrm~H{_O%|>%hN&?*UsE8CwJ10&WAp0JeeO0Hgn38~nSu zzw$I=-{Siba1;0^FxstMV(ca0H6X&VXRuc*@&GLc3Jm7#1?;$E`XKnknou@xz2QRL=fc%SB(mv!euakXT+U=3gsNY%!IUiVW8pY%$y#H%Lolf) z6^EJ{+&`9K8m*v2245qi0XY&&AJ>B!0r4mx_#;RFI{@SO5o5{|pU35Pt zo9ye%#P;a&ossmd&yu>JRotGTTzcL~x6^lVQy-I$Xnt&L?ha9kE*}nehqOD~ouDHS zb%jH1OnLg|hCr2tpLThgZk~Sbld##ehl`|*s}}2TU~*l$SVZ78|VSElL;op4iv`#%mgG48Vs!^Gr0wX~Tn;7;_9#4426SvN}kd rvfCz7U!{isisiyD7svn=1Bw}C)gQp}2N&zo*f*M;XT8oINr3$a0~$R% diff --git a/languages/sefa-fr_FR.po b/languages/sefa-fr_FR.po deleted file mode 100644 index ada10c5..0000000 --- a/languages/sefa-fr_FR.po +++ /dev/null @@ -1,74 +0,0 @@ -msgid "" -msgstr "" -"Project-Id-Version: Simple Email From Admin\n" -"POT-Creation-Date: 2015-10-28 13:05-0330\n" -"PO-Revision-Date: 2015-10-28 13:05-0330\n" -"Last-Translator: \n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 1.5.7\n" -"X-Poedit-KeywordsList: __;_e;_;gettext;gettext_noop\n" -"X-Poedit-Basepath: ../\n" -"X-Poedit-SearchPath-0: .\n" - -#: simple-email-from-admin.php:73 -msgid "Please enter an email recipient in the To: field." -msgstr "S'il vous plaît entrer une adresse e-mail dans le champ A:." - -#: simple-email-from-admin.php:87 -msgid "Please enter a Subject." -msgstr "S'il vous plaît entrer un sujet." - -#: simple-email-from-admin.php:88 -msgid "Please enter a Message." -msgstr "S'il vous plaît entrer un message." - -#: simple-email-from-admin.php:98 -msgid "Your email has been successfully sent!" -msgstr "Votre e-mail a été envoyé avec succès!" - -#: simple-email-from-admin.php:100 -msgid "There was an error sending the email." -msgstr "Il y avait une erreur d'envoi du courriel." - -#: simple-email-from-admin.php:105 -msgid "Your email has been successfully sent to " -msgstr "Votre courriel a été envoyé avec succès à " - -#: simple-email-from-admin.php:107 -msgid "There was an error sending the email to " -msgstr "Il y avait une erreur d'envoi de l'e-mail " - -#: simple-email-from-admin.php:115 -msgid "Send Email From Admin" -msgstr "" - -#: simple-email-from-admin.php:138 -msgid "These can be changed in Settings->General." -msgstr "Ceux-ci peuvent être modifiés en Settings->General." - -#: simple-email-from-admin.php:142 -msgid "" -"To send to multiple recipeints, enter each email address seperated by a " -"comma or choose from the user list below." -msgstr "" -"Pour envoyer à plusieurs destinataires, entrez chaque adresse mail séparée " -"par une virgule ou choisir parmi la liste des utilisateurs ci-dessous." - -#: simple-email-from-admin.php:144 -msgid "user list" -msgstr "la liste des utilisateurs" - -#: simple-email-from-admin.php:163 -msgid "Send each recipient an individual email" -msgstr "Envoyer un e-mail chaque destinataire individuel" - -#: simple-email-from-admin.php:166 -msgid "Send a group email to all recipients" -msgstr "Envoyer un e-mail de groupe à tous les destinataires" - -#: simple-email-from-admin.php:188 -msgid "Send Message" -msgstr "Envoyer le message" diff --git a/languages/sefa.pot b/languages/sefa.pot deleted file mode 100644 index cb3456e..0000000 --- a/languages/sefa.pot +++ /dev/null @@ -1,72 +0,0 @@ -msgid "" -msgstr "" -"Project-Id-Version: Simple Email From Admin\n" -"POT-Creation-Date: 2015-10-28 13:01-0330\n" -"PO-Revision-Date: 2015-10-28 13:01-0330\n" -"Last-Translator: \n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 1.5.7\n" -"X-Poedit-KeywordsList: __;_e;_;gettext;gettext_noop\n" -"X-Poedit-Basepath: ../\n" -"X-Poedit-SearchPath-0: .\n" - -#: simple-email-from-admin.php:73 -msgid "Please enter an email recipient in the To: field." -msgstr "" - -#: simple-email-from-admin.php:87 -msgid "Please enter a Subject." -msgstr "" - -#: simple-email-from-admin.php:88 -msgid "Please enter a Message." -msgstr "" - -#: simple-email-from-admin.php:98 -msgid "Your email has been successfully sent!" -msgstr "" - -#: simple-email-from-admin.php:100 -msgid "There was an error sending the email." -msgstr "" - -#: simple-email-from-admin.php:105 -msgid "Your email has been successfully sent to " -msgstr "" - -#: simple-email-from-admin.php:107 -msgid "There was an error sending the email to " -msgstr "" - -#: simple-email-from-admin.php:115 -msgid "Send Email From Admin" -msgstr "" - -#: simple-email-from-admin.php:138 -msgid "These can be changed in Settings->General." -msgstr "" - -#: simple-email-from-admin.php:142 -msgid "" -"To send to multiple recipeints, enter each email address seperated by a " -"comma or choose from the user list below." -msgstr "" - -#: simple-email-from-admin.php:144 -msgid "user list" -msgstr "" - -#: simple-email-from-admin.php:163 -msgid "Send each recipient an individual email" -msgstr "" - -#: simple-email-from-admin.php:166 -msgid "Send a group email to all recipients" -msgstr "" - -#: simple-email-from-admin.php:188 -msgid "Send Message" -msgstr "" diff --git a/readme.txt b/readme.txt deleted file mode 100644 index a80db0f..0000000 --- a/readme.txt +++ /dev/null @@ -1,66 +0,0 @@ -=== Send Email From Admin === -Contributors: kojak711 -Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8HHLL6WRX9Z68 -Tags: email, send email, admin email, custom email, email tools, email attachment -Requires at least: 4.0 -Tested up to: 6.2 -Stable tag: 1.0 -License: GPLv2 or later -License URI: http://www.gnu.org/licenses/gpl-2.0.html - -Easily send a simple custom email with an attachment from the WordPress administration screen. - -== Description == - -Send Email From Admin gives you the ability to easily send a custom HTML email from the WordPress administration screen. You can send to existing users or add your own recipients. You can send to multiple recipients and choose to send group emails or individual emails. Emails can also have an attachment. A new menu item called 'Send Email' is added under the Tools menu. This plugin is also translatable. - -NOTE: This is not intended to be a mass/bulk mailing plugin. This is a very lean plugin that is best suited to send an email to one or up to a handful of recipients. - -== Installation == - -1. Upload `send-email-from-admin` folder to the `/wp-content/plugins/` directory -2. Activate the plugin through the 'Plugins' menu in WordPress - -== Frequently Asked Questions == - -= Can I change the From name and From email address? = - -Yes. The plugin uses the values that you entered for Site Title and E-Mail Address in Settings->General. - -= Can I send to multiple recipients? = - -Yes. You have the option to send to multiple recipents and you can choose to send the email as an individual email to each recipient (each recipient will only see their own email address in the To: field) or as a group email (each recipient will see the other recipients in the To: field). - -= Can I add images to the email? = - -Yes. You can add images from the WordPress Media Library. - -= Can I add an attachment to the email? = - -Yes. You can upload and attach one attachment to the email message. - -== Screenshots == - -1. Send Email From Admin main screen. - -== Changelog == - -= 1.0 = -* fix typos - -= 0.9.3 = -* added links -* minor css changes - -= 0.9.2 = -* minor code cleanup -* added HTML5 'required' attribute to form fields -* js and css now only load on SEFA admin page - -= 0.9.1 = -* css and html cleanup -* added mail dashicon -* uploaded file (attachment) is now deleted from server after email is sent - -= 0.9 = -* Initial release \ No newline at end of file From 1251f097bcca1165691ce7ae7256b1614fd633d0 Mon Sep 17 00:00:00 2001 From: abuyoyo Date: Sat, 4 Jan 2025 09:15:31 +0200 Subject: [PATCH 05/13] Remove helper function swpm_plugin_issetor() --- send-wp-mail.php | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/send-wp-mail.php b/send-wp-mail.php index 86c8c5a..10b3ba8 100644 --- a/send-wp-mail.php +++ b/send-wp-mail.php @@ -167,7 +167,7 @@ function swpm_plugin_main() { -
    +
    + "200" ); - wp_editor( swpm_plugin_issetor($email_body), "email_body", $settings ); + wp_editor( $email_body ?? '', "email_body", $settings ); ?> @@ -240,16 +240,3 @@ function swpm_plugin_main() {
    Date: Thu, 7 Nov 2024 20:52:59 +0200 Subject: [PATCH 06/13] misc cleanup --- send-wp-mail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/send-wp-mail.php b/send-wp-mail.php index 10b3ba8..c56bcfb 100644 --- a/send-wp-mail.php +++ b/send-wp-mail.php @@ -180,7 +180,7 @@ function swpm_plugin_main() { } echo ''; }; - ?> + ?> From 059f67fd0c2b7bdb25b8e4c7d376d9b303613892 Mon Sep 17 00:00:00 2001 From: abuyoyo Date: Thu, 7 Nov 2024 20:55:22 +0200 Subject: [PATCH 07/13] jQuery 3.x compatibility --- js/send-wp-mail.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/send-wp-mail.js b/js/send-wp-mail.js index c174191..da3ad88 100644 --- a/js/send-wp-mail.js +++ b/js/send-wp-mail.js @@ -1,5 +1,5 @@ -jQuery( document ).ready( function( $ ) { - $("#swpm-user-list").change( function() { +jQuery( function( $ ) { + $("#swpm-user-list").on( 'change', function() { $recipients = $("#swpm-recipient-emails"); if ( $recipients.val() == '' ) { $recipients.val( $(this).find("option:selected").attr("value") ); From 219fdb8b2980405342257e129a7862878686fd94 Mon Sep 17 00:00:00 2001 From: abuyoyo Date: Sun, 10 Nov 2024 07:18:14 +0200 Subject: [PATCH 08/13] Notices - below-h2 --- send-wp-mail.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/send-wp-mail.php b/send-wp-mail.php index c56bcfb..24cd95e 100644 --- a/send-wp-mail.php +++ b/send-wp-mail.php @@ -120,16 +120,16 @@ function swpm_plugin_main() { if ( $group_email === 'yes' ) { if ( wp_mail( $email_to, $email_subject, $email_body, $headers, $attachments ) ) { - $send_mail_message = '
    ' . __( 'Your email has been successfully sent!', 'swpm' ) . '
    '; + $send_mail_message = '
    ' . __( 'Your email has been successfully sent!', 'swpm' ) . '
    '; } else { - $send_mail_message = '
    ' . __( 'There was an error sending the email.', 'swpm' ) . '
    '; + $send_mail_message = '
    ' . __( 'There was an error sending the email.', 'swpm' ) . '
    '; } } else { foreach( $recipients as $recipient ) { if ( wp_mail( $recipient, $email_subject, $email_body, $headers, $attachments ) ) { - $send_mail_message .= '
    ' . __( 'Your email has been successfully sent to ', 'swpm' ) . esc_html($recipient) . '!
    '; + $send_mail_message .= '
    ' . __( 'Your email has been successfully sent to ', 'swpm' ) . esc_html($recipient) . '!
    '; } else { - $send_mail_message .= '
    ' . __( 'There was an error sending the email to ', 'swpm' ) . esc_html($recipient) . '
    '; + $send_mail_message .= '
    ' . __( 'There was an error sending the email to ', 'swpm' ) . esc_html($recipient) . '
    '; } } } @@ -145,7 +145,7 @@ function swpm_plugin_main() {

      '; + echo '
        '; foreach ($errors as $error) { echo "
      • $error
      • "; } From ea03247c9c4b7a4161cf5e8200d5a5441e02d5c6 Mon Sep 17 00:00:00 2001 From: abuyoyo Date: Sun, 3 Nov 2024 22:51:52 +0200 Subject: [PATCH 09/13] Remove sidebar meta-box --- send-wp-mail.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/send-wp-mail.php b/send-wp-mail.php index 24cd95e..e806476 100644 --- a/send-wp-mail.php +++ b/send-wp-mail.php @@ -223,17 +223,8 @@ function swpm_plugin_main() {
      -
      -
      -

      Like this plugin?

      - -
      -
      +
    From 5ab49dd8c850ccc64239ef6aba6c7a8328ab25b6 Mon Sep 17 00:00:00 2001 From: abuyoyo Date: Sat, 4 Jan 2025 09:26:55 +0200 Subject: [PATCH 10/13] Default to group email --- css/send-wp-mail.css | 2 +- send-wp-mail.php | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/css/send-wp-mail.css b/css/send-wp-mail.css index 7835921..64e727b 100644 --- a/css/send-wp-mail.css +++ b/css/send-wp-mail.css @@ -48,7 +48,7 @@ padding: 6px 10px } #swpm-form .swpm-radio-wrap { - display: inline; + margin-bottom: 5px; } #swpm-form .wp-editor-wrap { padding-left: 0; diff --git a/send-wp-mail.php b/send-wp-mail.php index e806476..086ccc6 100644 --- a/send-wp-mail.php +++ b/send-wp-mail.php @@ -188,13 +188,12 @@ function swpm_plugin_main() {
    - required> - + required> +
    -    -
    - required> - +
    + required> +
    From 44993ed048040fbecd034cf7cb9cc81104ab7fdc Mon Sep 17 00:00:00 2001 From: abuyoyo Date: Sun, 3 Nov 2024 22:02:23 +0200 Subject: [PATCH 11/13] No email spoofing - use wp_mail_from + wp_mail_from_name - No spoofing. do not use admin user's email(!) when using wp_mail() - Do not set from email and name in headers - Attempt to re-create WordPress core's defaults in "from" input field. - Disabled input field "from" in not required. --- send-wp-mail.php | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/send-wp-mail.php b/send-wp-mail.php index 086ccc6..37842c6 100644 --- a/send-wp-mail.php +++ b/send-wp-mail.php @@ -55,11 +55,12 @@ add_action('plugins_loaded', 'swpm_plugin_load_textdomain'); * Our main function to display and process our form * * @since 0.9 + * @since 1.1 No more email spoofing - use wp_mail_from hook/default */ function swpm_plugin_main() { - // get site info to construct 'FROM' for email - $from_name = wp_specialchars_decode( get_option('blogname'), ENT_QUOTES ); - $from_email = get_bloginfo('admin_email'); + // get email and name from WordPress hooks if available. + $from_name = apply_filters( 'wp_mail_from_name', '' ); + $from_email = apply_filters( 'wp_mail_from', '' ); // initialize $send_mail_message = false; @@ -115,7 +116,7 @@ function swpm_plugin_main() { // send the email if no errors were found if ( empty($errors) ) { $headers[] = "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n"; - $headers[] = 'From: ' . $from_name . ' <' . $from_email . ">\r\n"; + // $headers[] = 'From: ' . $from_name . ' <' . $from_email . ">\r\n"; // We should let wp_mail handle the name and address. no spoofing. $attachments = $attachment_path; if ( $group_email === 'yes' ) { @@ -139,10 +140,28 @@ function swpm_plugin_main() { unlink($attachment_path); } } - } + } + + // reconstruct wp_mail defaults. + if ( empty( $from_email ) ) { + $from_email = 'wordpress@'; + $domain = wp_parse_url( network_home_url(), PHP_URL_HOST ); + if ( null !== $domain ) { + if ( str_starts_with( $domain, 'www.' ) ) { + $domain = substr( $domain, 4 ); + } + $from_email .= $domain; + } + } + + if ( empty( $from_name ) ) { + $from_name = 'WordPress'; + } + ?>

    +
    wp_mail() directly from this website.', 'swpm' ); ?>
      '; @@ -163,7 +182,7 @@ function swpm_plugin_main() { - + From 29f9cf7bef00c4ccf81488cc0eeb03b8142fa916 Mon Sep 17 00:00:00 2001 From: abuyoyo Date: Thu, 7 Nov 2024 20:54:35 +0200 Subject: [PATCH 12/13] Add admin email to user select options --- send-wp-mail.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/send-wp-mail.php b/send-wp-mail.php index 37842c6..31a1300 100644 --- a/send-wp-mail.php +++ b/send-wp-mail.php @@ -188,7 +188,8 @@ function swpm_plugin_main() {
      From:" required>
      General.', 'swpm' ); ?>
      ">
      wp_mail_from and wp_mail_from_name hooks.', 'swpm' ); ?>