updated plugin SMTP Mailer version 1.1.26

This commit is contained in:
2026-06-03 21:29:17 +00:00
committed by Gitium
parent e410ed67cf
commit bc89bee944
2 changed files with 178 additions and 30 deletions

View File

@ -1,7 +1,8 @@
<?php
/*
Plugin Name: SMTP Mailer
Version: 1.1.18
Version: 1.1.26
Requires at least: 7.0
Plugin URI: https://wphowto.net/smtp-mailer-plugin-for-wordpress-1482
Author: naa986
Author URI: https://wphowto.net/
@ -16,8 +17,8 @@ if (!defined('ABSPATH')){
class SMTP_MAILER {
var $plugin_version = '1.1.18';
var $phpmailer_version = '6.9.3';
var $plugin_version = '1.1.26';
var $phpmailer_version = '7.0.2';
var $plugin_url;
var $plugin_path;
@ -63,14 +64,16 @@ class SMTP_MAILER {
}
function plugin_url() {
if ($this->plugin_url)
if ($this->plugin_url){
return $this->plugin_url;
}
return $this->plugin_url = plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__));
}
function plugin_path() {
if ($this->plugin_path)
if ($this->plugin_path){
return $this->plugin_path;
}
return $this->plugin_path = untrailingslashit(plugin_dir_path(__FILE__));
}
@ -84,7 +87,7 @@ class SMTP_MAILER {
function options_menu() {
add_options_page(__('SMTP Mailer', 'smtp-mailer'), __('SMTP Mailer', 'smtp-mailer'), 'manage_options', 'smtp-mailer-settings', array($this, 'options_page'));
}
function options_page() {
$plugin_tabs = array(
'smtp-mailer-settings' => __('General', 'smtp-mailer'),
@ -94,7 +97,7 @@ class SMTP_MAILER {
'smtp-mailer-settings&action=advanced' => __('Advanced', 'smtp-mailer'),
);
$url = "https://wphowto.net/smtp-mailer-plugin-for-wordpress-1482";
$link_text = sprintf(__('Please visit the <a target="_blank" href="%s">SMTP Mailer</a> documentation page for usage instructions.', 'smtp-mailer'), esc_url($url));
$link_text = sprintf(__('Please visit the <a target="_blank" href="%s">SMTP Mailer</a> documentation page for setup instructions.', 'smtp-mailer'), esc_url($url));
$allowed_html_tags = array(
'a' => array(
'href' => array(),
@ -157,7 +160,7 @@ class SMTP_MAILER {
$this->general_settings();
}
echo '</div>';
}
}
function test_email_settings(){
if(isset($_POST['smtp_mailer_send_test_email'])){
@ -294,6 +297,14 @@ class SMTP_MAILER {
if(isset($_POST['from_name']) && !empty($_POST['from_name'])){
$from_name = sanitize_text_field(stripslashes($_POST['from_name']));
}
$force_from_name = '';
if(isset($_POST['force_from_name']) && !empty($_POST['force_from_name'])){
$force_from_name = sanitize_text_field($_POST['force_from_name']);
}
$force_from_email = '';
if(isset($_POST['force_from_email']) && !empty($_POST['force_from_email'])){
$force_from_email = sanitize_text_field($_POST['force_from_email']);
}
$force_from_address = '';
if(isset($_POST['force_from_address']) && !empty($_POST['force_from_address'])){
$force_from_address = sanitize_text_field($_POST['force_from_address']);
@ -313,19 +324,40 @@ class SMTP_MAILER {
$options['smtp_port'] = $smtp_port;
$options['from_email'] = $from_email;
$options['from_name'] = $from_name;
$options['force_from_name'] = $force_from_name;
$options['force_from_email'] = $force_from_email;
$options['force_from_address'] = $force_from_address;
$options['disable_ssl_verification'] = $disable_ssl_verification;
smtp_mailer_update_option($options);
echo '<div id="message" class="updated fade"><p><strong>';
echo __('Settings Saved!', 'smtp-mailer');
echo '</strong></p></div>';
}
}
//
if (isset($_POST['smtp_mailer_delete_options'])) {
if(check_admin_referer('smtp_mailer_delete_options', 'smtp_mailer_delete_options_nonce')) {
delete_option('smtp_mailer_options');
echo '<div id="message" class="updated fade"><p><strong>';
echo __('Options deleted!', 'smtp-mailer');
echo '</strong></p></div>';
}
}
$options = smtp_mailer_get_option();
if(!is_array($options)){
$options = smtp_mailer_get_empty_options_array();
}
// Avoid warning notice since this option was added later
if(!isset($options['force_from_name'])){
$options['force_from_name'] = '';
}
// Avoid warning notice since this option was added later
if(!isset($options['force_from_email'])){
$options['force_from_email'] = '';
}
// Avoid warning notice since this option was added later
if(!isset($options['force_from_address'])){
$options['force_from_address'] = '';
@ -404,6 +436,18 @@ class SMTP_MAILER {
<p class="description"><?php _e('The name which will be used as the From Name if it is not supplied to the mail function.', 'smtp-mailer');?></p></td>
</tr>
<tr valign="top">
<th scope="row"><label for="force_from_name"><?php _e('Force From Name', 'smtp-mailer');?></label></th>
<td><input name="force_from_name" type="checkbox" id="force_from_name" <?php checked($options['force_from_name'], 1); ?> value="1">
<p class="description"><?php _e('The From name in the settings will be set for all outgoing email messages.', 'smtp-mailer');?></p></td>
</tr>
<tr valign="top">
<th scope="row"><label for="force_from_email"><?php _e('Force From Email', 'smtp-mailer');?></label></th>
<td><input name="force_from_email" type="checkbox" id="force_from_email" <?php checked($options['force_from_email'], 1); ?> value="1">
<p class="description"><?php _e('The From email in the settings will be set for all outgoing email messages.', 'smtp-mailer');?></p></td>
</tr>
<tr valign="top">
<th scope="row"><label for="force_from_address"><?php _e('Force From Address', 'smtp-mailer');?></label></th>
<td><input name="force_from_address" type="checkbox" id="force_from_address" <?php checked($options['force_from_address'], 1); ?> value="1">
@ -422,6 +466,10 @@ class SMTP_MAILER {
<p class="submit"><input type="submit" name="smtp_mailer_update_settings" id="smtp_mailer_update_settings" class="button button-primary" value="<?php _e('Save Changes', 'smtp-mailer')?>"></p>
</form>
<form method="post" onsubmit="return confirm('Are you sure you want to delete saved options and start fresh?');">
<?php wp_nonce_field('smtp_mailer_delete_options', 'smtp_mailer_delete_options_nonce'); ?>
<p class="submit"><input type="submit" name="smtp_mailer_delete_options" id="smtp_mailer_delete_options" class="button" value="<?php _e('Delete Saved Options', 'smtp-mailer')?>"></p>
</form>
<?php
}
@ -496,6 +544,8 @@ function smtp_mailer_get_empty_options_array(){
$options['smtp_port'] = '';
$options['from_email'] = '';
$options['from_name'] = '';
$options['force_from_name'] = '';
$options['force_from_email'] = '';
$options['force_from_address'] = '';
$options['disable_ssl_verification'] = '';
return $options;
@ -574,6 +624,13 @@ function smtp_mailer_pre_wp_mail($null, $atts)
}
}
if ( isset( $atts['embeds'] ) ) {
$embeds = $atts['embeds'];
if ( ! is_array( $embeds ) ) {
$embeds = explode( "\n", str_replace( "\r\n", "\n", $embeds ) );
}
}
$options = smtp_mailer_get_option();
global $phpmailer;
@ -658,6 +715,9 @@ function smtp_mailer_pre_wp_mail($null, $atts)
} elseif ( false !== stripos( $charset_content, 'boundary=' ) ) {
$boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) );
$charset = '';
if ( preg_match( '~^multipart/(\S+)~', $content_type, $matches ) ) {
$content_type = 'multipart/' . strtolower( $matches[1] ) . '; boundary="' . $boundary . '"';
}
}
// Avoid setting an empty $content_type.
@ -691,6 +751,15 @@ function smtp_mailer_pre_wp_mail($null, $atts)
$phpmailer->Body = '';
$phpmailer->AltBody = '';
/*
* Reset encoding to 8-bit, as it may have been automatically downgraded
* to 7-bit by PHPMailer (based on the body contents) in a previous call
* to wp_mail().
*
* See https://core.trac.wordpress.org/ticket/33972
*/
$phpmailer->Encoding = PHPMailer\PHPMailer\PHPMailer::ENCODING_8BIT;
// Set "From" name and email.
// If we don't have a name from the input headers.
@ -737,13 +806,21 @@ function smtp_mailer_pre_wp_mail($null, $atts)
* @param string $from_name Name associated with the "from" email address.
*/
$from_name = apply_filters( 'wp_mail_from_name', $from_name );
//force from name if checked
if(isset($options['force_from_name']) && !empty($options['force_from_name'])){
$from_name = $options['from_name'];
}
//force from email if checked
if(isset($options['force_from_email']) && !empty($options['force_from_email'])){
$from_email = $options['from_email'];
}
//force from address if checked
if(isset($options['force_from_address']) && !empty($options['force_from_address'])){
$from_name = $options['from_name'];
$from_email = $options['from_email'];
}
try {
$phpmailer->setFrom( $from_email, $from_name, false );
$phpmailer->setFrom( $from_email, $from_name );
} catch ( PHPMailer\PHPMailer\Exception $e ) {
$mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
$mail_error_data['phpmailer_exception_code'] = $e->getCode();
@ -794,10 +871,10 @@ function smtp_mailer_pre_wp_mail($null, $atts)
$phpmailer->addAddress( $address, $recipient_name );
break;
case 'cc':
$phpmailer->addCc( $address, $recipient_name );
$phpmailer->addCC( $address, $recipient_name );
break;
case 'bcc':
$phpmailer->addBcc( $address, $recipient_name );
$phpmailer->addBCC( $address, $recipient_name );
break;
case 'reply_to':
$phpmailer->addReplyTo( $address, $recipient_name );
@ -834,9 +911,11 @@ function smtp_mailer_pre_wp_mail($null, $atts)
$phpmailer->SMTPAutoTLS = false;
//enable debug when sending a test mail
if(isset($_POST['smtp_mailer_send_test_email'])){
$phpmailer->SMTPDebug = 4;
// Ask for HTML-friendly debug output
$phpmailer->Debugoutput = 'html';
if(is_admin() && current_user_can('manage_options')){
$phpmailer->SMTPDebug = 4;
// Ask for HTML-friendly debug output
$phpmailer->Debugoutput = 'html';
}
}
//disable ssl certificate verification if checked
@ -898,10 +977,6 @@ function smtp_mailer_pre_wp_mail($null, $atts)
}
}
}
if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) {
$phpmailer->addCustomHeader( sprintf( 'Content-Type: %s; boundary="%s"', $content_type, $boundary ) );
}
}
if ( isset( $attachments ) && ! empty( $attachments ) ) {
@ -915,6 +990,51 @@ function smtp_mailer_pre_wp_mail($null, $atts)
}
}
}
if ( isset( $embeds ) && ! empty( $embeds ) ) {
foreach ( $embeds as $key => $embed_path ) {
/**
* Filters the arguments for PHPMailer's addEmbeddedImage() method.
*
* @since 6.9.0
*
* @param array $args {
* An array of arguments for PHPMailer's addEmbeddedImage() method.
*
* @type string $path The path to the file.
* @type string $cid The Content-ID of the image. Default: The key in the embeds array.
* @type string $name The filename of the image.
* @type string $encoding The encoding of the image. Default: 'base64'.
* @type string $type The MIME type of the image. Default: empty string, which lets PHPMailer auto-detect.
* @type string $disposition The disposition of the image. Default: 'inline'.
* }
*/
$embed_args = apply_filters(
'wp_mail_embed_args',
array(
'path' => $embed_path,
'cid' => (string) $key,
'name' => basename( $embed_path ),
'encoding' => 'base64',
'type' => '',
'disposition' => 'inline',
)
);
try {
$phpmailer->addEmbeddedImage(
$embed_args['path'],
$embed_args['cid'],
$embed_args['name'],
$embed_args['encoding'],
$embed_args['type'],
$embed_args['disposition']
);
} catch ( PHPMailer\PHPMailer\Exception $e ) {
continue;
}
}
}
/**
* Fires after PHPMailer is initialized.
@ -925,7 +1045,7 @@ function smtp_mailer_pre_wp_mail($null, $atts)
*/
do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
$mail_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
$mail_data = compact( 'to', 'subject', 'message', 'headers', 'attachments', 'embeds' );
// Send!
try {
@ -939,15 +1059,17 @@ function smtp_mailer_pre_wp_mail($null, $atts)
* process the request without any errors.
*
* @since 5.9.0
* @since 6.9.0 The `$embeds` element was added to the `$mail_data` array.
*
* @param array $mail_data {
* An array containing the email recipient(s), subject, message, headers, and attachments.
* An array containing the email recipient(s), subject, message, headers, attachments, and embeds.
*
* @type string[] $to Email addresses to send message.
* @type string $subject Email subject.
* @type string $message Message contents.
* @type string[] $headers Additional headers.
* @type string[] $attachments Paths to files to attach.
* @type string[] $embeds Paths to files to embed.
* }
*/
do_action( 'wp_mail_succeeded', $mail_data );
@ -957,12 +1079,12 @@ function smtp_mailer_pre_wp_mail($null, $atts)
$mail_data['phpmailer_exception_code'] = $e->getCode();
/**
* Fires after a PHPMailer\PHPMailer\Exception is caught.
* Fires after a PHPMailer exception is caught.
*
* @since 4.4.0
*
* @param WP_Error $error A WP_Error object with the PHPMailer\PHPMailer\Exception message, and an array
* containing the mail recipient, subject, message, headers, and attachments.
* containing the mail recipient, subject, message, headers, attachments, and embeds.
*/
do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_data ) );