|
|
|
|
@ -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,21 +116,21 @@ 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' ) {
|
|
|
|
|
if ( wp_mail( $email_to, $email_subject, $email_body, $headers, $attachments ) ) {
|
|
|
|
|
$send_mail_message = '<div class="updated">' . __( 'Your email has been successfully sent!', 'swpm' ) . '</div>';
|
|
|
|
|
$send_mail_message = '<div class="below-h2 updated">' . __( 'Your email has been successfully sent!', 'swpm' ) . '</div>';
|
|
|
|
|
} else {
|
|
|
|
|
$send_mail_message = '<div class="error">' . __( 'There was an error sending the email.', 'swpm' ) . '</div>';
|
|
|
|
|
$send_mail_message = '<div class="below-h2 error">' . __( 'There was an error sending the email.', 'swpm' ) . '</div>';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
foreach( $recipients as $recipient ) {
|
|
|
|
|
if ( wp_mail( $recipient, $email_subject, $email_body, $headers, $attachments ) ) {
|
|
|
|
|
$send_mail_message .= '<div class="updated">' . __( 'Your email has been successfully sent to ', 'swpm' ) . esc_html($recipient) . '!</div>';
|
|
|
|
|
$send_mail_message .= '<div class="below-h2 updated">' . __( 'Your email has been successfully sent to ', 'swpm' ) . esc_html($recipient) . '!</div>';
|
|
|
|
|
} else {
|
|
|
|
|
$send_mail_message .= '<div class="error">' . __( 'There was an error sending the email to ', 'swpm' ) . esc_html($recipient) . '</div>';
|
|
|
|
|
$send_mail_message .= '<div class="below-h2 error">' . __( 'There was an error sending the email to ', 'swpm' ) . esc_html($recipient) . '</div>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -139,13 +140,31 @@ 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';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
<div class="wrap" id="swpm-wrapper">
|
|
|
|
|
<h1><?php _e( 'Send WP Mail', 'swpm' ); ?></h1>
|
|
|
|
|
<div class="card"><?php _e( 'Send email using WordPress core <code>wp_mail()</code> directly from this website.', 'swpm' ); ?></div>
|
|
|
|
|
<?php
|
|
|
|
|
if ( !empty($errors) ) {
|
|
|
|
|
echo '<div class="error"><ul>';
|
|
|
|
|
echo '<div class="below-h2 error"><ul>';
|
|
|
|
|
foreach ($errors as $error) {
|
|
|
|
|
echo "<li>$error</li>";
|
|
|
|
|
}
|
|
|
|
|
@ -163,13 +182,14 @@ function swpm_plugin_main() {
|
|
|
|
|
<table cellpadding="0" border="0" class="form-table">
|
|
|
|
|
<tr>
|
|
|
|
|
<th scope=”row”>From:</th>
|
|
|
|
|
<td><input type="text" disabled value="<?php echo "$from_name <$from_email>"; ?>" required><div class="note"><?php _e( 'These can be changed in Settings->General.', 'swpm' ); ?></div></td>
|
|
|
|
|
<td><input type="text" disabled value="<?php echo "$from_name <$from_email>"; ?>"><div class="note"><?php _e( 'These can be changed using <code>wp_mail_from</code> and <code>wp_mail_from_name</code> hooks.', 'swpm' ); ?></div></td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<th scope=”row”><label for="swpm-recipient-emails">To:</label></th>
|
|
|
|
|
<td><input type="email" multiple id="swpm-recipient-emails" name="email_to" value="<?php echo esc_attr( swpm_plugin_issetor($email_to) ); ?>" required><div class="note"><?php _e( 'To send to multiple recipients, enter each email address separated by a comma or choose from the user list below.', 'swpm' ); ?></div>
|
|
|
|
|
<td><input type="email" multiple id="swpm-recipient-emails" name="email_to" value="<?php echo esc_attr( $email_to ?? '' ); ?>" required><div class="note"><?php _e( 'To send to multiple recipients, enter each email address separated by a comma or choose from the user list below.', 'swpm' ); ?></div>
|
|
|
|
|
<select id="swpm-user-list">
|
|
|
|
|
<option value="">-- <?php _e( 'user list', 'swpm' ); ?> --</option>
|
|
|
|
|
<option value="">-- <?php _e( 'Select Email(s)', 'swpm' ); ?> --</option>
|
|
|
|
|
<option value="<?php echo get_option('admin_email') ?>">Administration Email <<?php echo get_option('admin_email') ?>></option>
|
|
|
|
|
<?php
|
|
|
|
|
$users = get_users( 'orderby=user_email' );
|
|
|
|
|
foreach ( $users as $user ) {
|
|
|
|
|
@ -180,7 +200,7 @@ function swpm_plugin_main() {
|
|
|
|
|
}
|
|
|
|
|
echo '<option value="' . esc_html( $user->user_email ) . '">' . esc_html( $user->user_email ) . esc_html( $user_fullname) . '</option>';
|
|
|
|
|
};
|
|
|
|
|
?>
|
|
|
|
|
?>
|
|
|
|
|
</select>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
@ -188,26 +208,25 @@ function swpm_plugin_main() {
|
|
|
|
|
<th scope=”row”></th>
|
|
|
|
|
<td>
|
|
|
|
|
<div class="swpm-radio-wrap">
|
|
|
|
|
<input type="radio" class="radio" name="group_email" value="no" id="no"<?php if ( isset($group_email) && $group_email === 'no' ) echo ' checked'; ?> required>
|
|
|
|
|
<label for="no"><?php _e( 'Send each recipient an individual email', 'swpm' ); ?></label>
|
|
|
|
|
<input type="radio" class="radio" name="group_email" value="yes" id="yes"<?php checked( ! isset($group_email) || $group_email === 'yes' ) ?> required>
|
|
|
|
|
<label for="yes"><?php _e( 'Send a group email to all recipients', 'swpm' ); ?></label>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="swpm-radio-wrap">
|
|
|
|
|
<input type="radio" class="radio" name="group_email" value="yes" id="yes"<?php if ( isset($group_email) && $group_email === 'yes' ) echo ' checked'; ?> required>
|
|
|
|
|
<label for="yes"><?php _e( 'Send a group email to all recipients', 'swpm' ); ?></label>
|
|
|
|
|
<div class="swpm-radio-wrap">
|
|
|
|
|
<input type="radio" class="radio" name="group_email" value="no" id="no"<?php checked( isset($group_email) && $group_email === 'no' ) ?> required>
|
|
|
|
|
<label for="no"><?php _e( 'Send each recipient an individual email', 'swpm' ); ?></label>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<th scope=”row”><label for="swpm-subject">Subject:</label></th>
|
|
|
|
|
<td><input type="text" id="swpm-subject" name="email_subject" value="<?php echo esc_attr( swpm_plugin_issetor($email_subject) );?>" required></td>
|
|
|
|
|
<td><input type="text" id="swpm-subject" name="email_subject" value="<?php echo esc_attr( $email_subject ?? '' );?>" required></td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<th scope=”row”><label for="email_body">Message:</label></th>
|
|
|
|
|
<td align="left">
|
|
|
|
|
<?php
|
|
|
|
|
$settings = array( "editor_height" => "200" );
|
|
|
|
|
wp_editor( swpm_plugin_issetor($email_body), "email_body", $settings );
|
|
|
|
|
wp_editor( $email_body ?? '', "email_body", $settings );
|
|
|
|
|
?>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
@ -223,33 +242,11 @@ function swpm_plugin_main() {
|
|
|
|
|
</table>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="postbox-container-1" class="postbox-container">
|
|
|
|
|
<div class="postbox">
|
|
|
|
|
<h3><span>Like this plugin?</span></h3>
|
|
|
|
|
<div class="inside">
|
|
|
|
|
<ul>
|
|
|
|
|
<li><a href="https://wordpress.org/support/view/plugin-reviews/send-email-from-admin?filter=5" target="_blank">Rate it on WordPress.org</a></li>
|
|
|
|
|
<li><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8HHLL6WRX9Z68" target="_blank">Donate to the developer</a></li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div> <!-- .inside -->
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<!-- <div id="postbox-container-1" class="postbox-container">
|
|
|
|
|
</div> -->
|
|
|
|
|
<div class="clear"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<?php
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper function for form values
|
|
|
|
|
*
|
|
|
|
|
* @since 0.9
|
|
|
|
|
*
|
|
|
|
|
* @param string $var Var name to test isset
|
|
|
|
|
*
|
|
|
|
|
* @return string $var value if isset or ''
|
|
|
|
|
*/
|
|
|
|
|
function swpm_plugin_issetor(&$var) {
|
|
|
|
|
return isset($var) ? $var : '';
|
|
|
|
|
}
|