wp-mail-smtp
Last commit date
assets
1 year ago
src
1 year ago
vendor
1 year ago
vendor_prefixed
1 year ago
readme.txt
1 year ago
uninstall.php
1 year ago
wp-mail-smtp.php
1 year ago
wp_mail_smtp.php
1 year ago
wp_mail_smtp.php
350 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: WP Mail SMTP |
| 4 | * Version: 4.4.0 |
| 5 | * Requires at least: 5.5 |
| 6 | * Requires PHP: 7.2 |
| 7 | * Plugin URI: https://wpmailsmtp.com/ |
| 8 | * Description: Reconfigures the <code>wp_mail()</code> function to use Gmail/Mailgun/SendGrid/SMTP instead of the default <code>mail()</code> and creates an options page to manage the settings. |
| 9 | * Author: WP Mail SMTP |
| 10 | * Author URI: https://wpmailsmtp.com/ |
| 11 | * Network: false |
| 12 | * Text Domain: wp-mail-smtp |
| 13 | * Domain Path: /assets/languages |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * @author WPForms |
| 18 | * @copyright WPForms, 2007-23, All Rights Reserved |
| 19 | * This code is released under the GPL licence version 3 or later, available here |
| 20 | * https://www.gnu.org/licenses/gpl.txt |
| 21 | */ |
| 22 | |
| 23 | /** |
| 24 | * Setting options in wp-config.php |
| 25 | * |
| 26 | * Specifically aimed at WP Multisite users, you can set the options for this plugin as |
| 27 | * constants in wp-config.php. Copy the code below into wp-config.php and tweak settings. |
| 28 | * Values from constants are NOT stripslash()'ed. |
| 29 | * |
| 30 | * When enabled, make sure to comment out (at the beginning of the line using //) those constants that you do not need, |
| 31 | * or remove them completely, so they won't interfere with plugin settings. |
| 32 | */ |
| 33 | |
| 34 | /* |
| 35 | define( 'WPMS_ON', true ); // True turns on the whole constants support and usage, false turns it off. |
| 36 | |
| 37 | define( 'WPMS_DO_NOT_SEND', true ); // Or false, in that case constant is ignored. |
| 38 | |
| 39 | define( 'WPMS_MAIL_FROM', 'mail@example.com' ); |
| 40 | define( 'WPMS_MAIL_FROM_FORCE', true ); // True turns it on, false turns it off. |
| 41 | define( 'WPMS_MAIL_FROM_NAME', 'From Name' ); |
| 42 | define( 'WPMS_MAIL_FROM_NAME_FORCE', true ); // True turns it on, false turns it off. |
| 43 | define( 'WPMS_MAILER', 'sendinblue' ); // Possible values: 'mail', 'smtpcom', 'sendinblue', 'mailgun', 'sendgrid', 'gmail', 'smtp'. |
| 44 | define( 'WPMS_SET_RETURN_PATH', true ); // Sets $phpmailer->Sender if true, relevant only for Other SMTP mailer. |
| 45 | |
| 46 | // Recommended mailers. |
| 47 | define( 'WPMS_SMTPCOM_API_KEY', '' ); |
| 48 | define( 'WPMS_SMTPCOM_CHANNEL', '' ); |
| 49 | define( 'WPMS_SENDINBLUE_API_KEY', '' ); |
| 50 | define( 'WPMS_SENDINBLUE_DOMAIN', '' ); |
| 51 | |
| 52 | define( 'WPMS_ZOHO_DOMAIN', '' ); |
| 53 | define( 'WPMS_ZOHO_CLIENT_ID', '' ); |
| 54 | define( 'WPMS_ZOHO_CLIENT_SECRET', '' ); |
| 55 | |
| 56 | define( 'WPMS_PEPIPOST_API_KEY', '' ); |
| 57 | |
| 58 | define( 'WPMS_SENDINBLUE_API_KEY', '' ); |
| 59 | |
| 60 | define( 'WPMS_MAILGUN_API_KEY', '' ); |
| 61 | define( 'WPMS_MAILGUN_DOMAIN', '' ); |
| 62 | define( 'WPMS_MAILGUN_REGION', 'US' ); // or 'EU' for Europe. |
| 63 | |
| 64 | define( 'WPMS_SENDGRID_API_KEY', '' ); |
| 65 | |
| 66 | define( 'WPMS_GMAIL_CLIENT_ID', '' ); |
| 67 | define( 'WPMS_GMAIL_CLIENT_SECRET', '' ); |
| 68 | |
| 69 | define( 'WPMS_SMTP_HOST', 'localhost' ); // The SMTP mail host. |
| 70 | define( 'WPMS_SMTP_PORT', 25 ); // The SMTP server port number. |
| 71 | define( 'WPMS_SSL', '' ); // Possible values '', 'ssl', 'tls' - note TLS is not STARTTLS. |
| 72 | define( 'WPMS_SMTP_AUTH', true ); // True turns it on, false turns it off. |
| 73 | define( 'WPMS_SMTP_USER', 'username' ); // SMTP authentication username, only used if WPMS_SMTP_AUTH is true. |
| 74 | define( 'WPMS_SMTP_PASS', 'password' ); // SMTP authentication password, only used if WPMS_SMTP_AUTH is true. |
| 75 | define( 'WPMS_SMTP_AUTOTLS', true ); // True turns it on, false turns it off. |
| 76 | */ |
| 77 | |
| 78 | /** |
| 79 | * Don't allow multiple versions of 1.5.x (Lite and Pro) and above to be active. |
| 80 | * |
| 81 | * @since 1.5.0 |
| 82 | */ |
| 83 | if ( function_exists( 'wp_mail_smtp' ) ) { |
| 84 | |
| 85 | if ( ! function_exists( 'wp_mail_smtp_deactivate' ) ) { |
| 86 | /** |
| 87 | * Deactivate if plugin already activated. |
| 88 | * Needed when transitioning from 1.5+ Lite to Pro. |
| 89 | * |
| 90 | * @since 1.5.0 |
| 91 | */ |
| 92 | function wp_mail_smtp_deactivate() { |
| 93 | /* |
| 94 | * Prevent issues of WP functions not being available for other plugins that hook into |
| 95 | * this early deactivation. GH issue #861. |
| 96 | */ |
| 97 | require_once ABSPATH . WPINC . '/pluggable.php'; |
| 98 | |
| 99 | deactivate_plugins( plugin_basename( __FILE__ ) ); |
| 100 | } |
| 101 | } |
| 102 | add_action( 'admin_init', 'wp_mail_smtp_deactivate' ); |
| 103 | |
| 104 | // Do not process the plugin code further. |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | if ( ! function_exists( 'wp_mail_smtp_check_pro_loading_allowed' ) ) { |
| 109 | /** |
| 110 | * Don't allow 1.4.x and below to break when 1.5+ Pro is activated. |
| 111 | * This will stop the current plugin from loading and display a message in admin area. |
| 112 | * |
| 113 | * @since 1.5.0 |
| 114 | */ |
| 115 | function wp_mail_smtp_check_pro_loading_allowed() { |
| 116 | |
| 117 | // Check for pro without using wp_mail_smtp()->is_pro(), because at this point it's too early. |
| 118 | if ( ! is_readable( rtrim( plugin_dir_path( __FILE__ ), '/\\' ) . '/src/Pro/Pro.php' ) ) { |
| 119 | // Currently, not a pro version of the plugin is loaded. |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | if ( ! function_exists( 'is_plugin_active' ) ) { |
| 124 | require_once ABSPATH . '/wp-admin/includes/plugin.php'; |
| 125 | } |
| 126 | |
| 127 | $lite_plugin_slug = 'wp-mail-smtp/wp_mail_smtp.php'; |
| 128 | |
| 129 | // Search for old plugin name. |
| 130 | if ( is_plugin_active( $lite_plugin_slug ) ) { |
| 131 | /* |
| 132 | * Prevent issues of WP functions not being available for other plugins that hook into |
| 133 | * this early deactivation. GH issue #861. |
| 134 | */ |
| 135 | require_once ABSPATH . WPINC . '/pluggable.php'; |
| 136 | |
| 137 | if ( |
| 138 | is_multisite() && |
| 139 | is_plugin_active_for_network( plugin_basename( __FILE__ ) ) && |
| 140 | ! is_plugin_active_for_network( $lite_plugin_slug ) |
| 141 | ) { |
| 142 | // Deactivate Lite plugin if Pro activated on Network level. |
| 143 | deactivate_plugins( $lite_plugin_slug ); |
| 144 | } else { |
| 145 | // As Pro is loaded and Lite too - deactivate *silently* itself not to break older SMTP plugin. |
| 146 | deactivate_plugins( plugin_basename( __FILE__ ) ); |
| 147 | |
| 148 | if ( is_network_admin() ) { |
| 149 | add_action( 'network_admin_notices', 'wp_mail_smtp_lite_deactivation_notice' ); |
| 150 | } else { |
| 151 | add_action( 'admin_notices', 'wp_mail_smtp_lite_deactivation_notice' ); |
| 152 | } |
| 153 | |
| 154 | return true; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | if ( ! function_exists( 'wp_mail_smtp_lite_deactivation_notice' ) ) { |
| 162 | /** |
| 163 | * Display the notice after deactivation. |
| 164 | * |
| 165 | * @since 1.5.0 |
| 166 | */ |
| 167 | function wp_mail_smtp_lite_deactivation_notice() { |
| 168 | |
| 169 | echo '<div class="notice notice-warning"><p>' . esc_html__( 'Please deactivate the free version of the WP Mail SMTP plugin before activating WP Mail SMTP Pro.', 'wp-mail-smtp' ) . '</p></div>'; |
| 170 | |
| 171 | if ( isset( $_GET['activate'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 172 | unset( $_GET['activate'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // Stop the plugin loading. |
| 178 | if ( wp_mail_smtp_check_pro_loading_allowed() === true ) { |
| 179 | return; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | if ( ! function_exists( 'wp_mail_smtp_insecure_php_version_notice' ) ) { |
| 184 | /** |
| 185 | * Display admin notice, if the server is using old/insecure PHP version. |
| 186 | * |
| 187 | * @since 2.0.0 |
| 188 | */ |
| 189 | function wp_mail_smtp_insecure_php_version_notice() { |
| 190 | |
| 191 | ?> |
| 192 | <div class="notice notice-error"> |
| 193 | <p> |
| 194 | <?php |
| 195 | printf( |
| 196 | wp_kses( /* translators: %1$s - WPBeginner URL for recommended WordPress hosting. */ |
| 197 | __( 'Your site is running an <strong>insecure version</strong> of PHP that is no longer supported. Please contact your web hosting provider to update your PHP version or switch to a <a href="%1$s" target="_blank" rel="noopener noreferrer">recommended WordPress hosting company</a>.', 'wp-mail-smtp' ), |
| 198 | array( |
| 199 | 'a' => array( |
| 200 | 'href' => array(), |
| 201 | 'target' => array(), |
| 202 | 'rel' => array(), |
| 203 | ), |
| 204 | 'strong' => array(), |
| 205 | ) |
| 206 | ), |
| 207 | 'https://www.wpbeginner.com/wordpress-hosting/' |
| 208 | ); |
| 209 | ?> |
| 210 | <br><br> |
| 211 | <?php |
| 212 | |
| 213 | $doc_link = add_query_arg( |
| 214 | [ |
| 215 | 'utm_source' => 'WordPress', |
| 216 | 'utm_medium' => 'Admin Notice', |
| 217 | 'utm_campaign' => is_readable( rtrim( plugin_dir_path( __FILE__ ), '/\\' ) . '/src/Pro/Pro.php' ) ? 'plugin' : 'liteplugin', |
| 218 | 'utm_content' => 'Minimal Required PHP Version', |
| 219 | ], |
| 220 | 'https://wpmailsmtp.com/docs/supported-php-versions-for-wp-mail-smtp/' |
| 221 | ); |
| 222 | |
| 223 | printf( |
| 224 | wp_kses( /* translators: %s - WPMailSMTP.com docs URL with more details. */ |
| 225 | __( '<strong>WP Mail SMTP plugin is disabled</strong> on your site until you fix the issue. <a href="%s" target="_blank" rel="noopener noreferrer">Read more for additional information.</a>', 'wp-mail-smtp' ), |
| 226 | array( |
| 227 | 'a' => array( |
| 228 | 'href' => array(), |
| 229 | 'target' => array(), |
| 230 | 'rel' => array(), |
| 231 | ), |
| 232 | 'strong' => array(), |
| 233 | ) |
| 234 | ), |
| 235 | esc_url( $doc_link ) |
| 236 | ); |
| 237 | ?> |
| 238 | </p> |
| 239 | </div> |
| 240 | |
| 241 | <?php |
| 242 | |
| 243 | // In case this is on plugin activation. |
| 244 | if ( isset( $_GET['activate'] ) ) { //phpcs:ignore |
| 245 | unset( $_GET['activate'] ); //phpcs:ignore |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | if ( ! defined( 'WPMS_PLUGIN_VER' ) ) { |
| 251 | /** |
| 252 | * Plugin version. |
| 253 | * |
| 254 | * @since 0.11.1 |
| 255 | */ |
| 256 | define( 'WPMS_PLUGIN_VER', '4.4.0' ); |
| 257 | } |
| 258 | if ( ! defined( 'WPMS_PHP_VER' ) ) { |
| 259 | /** |
| 260 | * Minimum supported PHP version. |
| 261 | * |
| 262 | * @since 1.0.0 |
| 263 | */ |
| 264 | define( 'WPMS_PHP_VER', '7.2' ); |
| 265 | } |
| 266 | if ( ! defined( 'WPMS_WP_VER' ) ) { |
| 267 | /** |
| 268 | * Minimum supported WordPress version. |
| 269 | * |
| 270 | * @since 3.3.0 |
| 271 | */ |
| 272 | define( 'WPMS_WP_VER', '5.5' ); |
| 273 | } |
| 274 | if ( ! defined( 'WPMS_PLUGIN_FILE' ) ) { |
| 275 | /** |
| 276 | * Plugin main file path. |
| 277 | * |
| 278 | * @since 2.1.2 |
| 279 | */ |
| 280 | define( 'WPMS_PLUGIN_FILE', __FILE__ ); |
| 281 | } |
| 282 | |
| 283 | if ( ! function_exists( 'wp_mail_smtp_unsupported_wp_version_notice' ) ) { |
| 284 | /** |
| 285 | * Display admin notice, if the site is using unsupported WP version. |
| 286 | * |
| 287 | * @since 3.3.0 |
| 288 | */ |
| 289 | function wp_mail_smtp_unsupported_wp_version_notice() { |
| 290 | |
| 291 | ?> |
| 292 | <div class="notice notice-error"> |
| 293 | <p> |
| 294 | <?php |
| 295 | printf( |
| 296 | wp_kses( /* translators: %s The minimal WP version supported by WP Mail SMTP. */ |
| 297 | __( 'Your site is running an <strong>old version</strong> of WordPress that is no longer supported by WP Mail SMTP. Please update your WordPress site to at least version <strong>%s</strong>.', 'wp-mail-smtp' ), |
| 298 | [ |
| 299 | 'strong' => [], |
| 300 | ] |
| 301 | ), |
| 302 | esc_html( WPMS_WP_VER ) |
| 303 | ); |
| 304 | ?> |
| 305 | <br><br> |
| 306 | <?php |
| 307 | echo wp_kses( |
| 308 | __( '<strong>WP Mail SMTP plugin is disabled</strong> on your site until WordPress is updated to the required version.', 'wp-mail-smtp' ), |
| 309 | [ |
| 310 | 'strong' => [], |
| 311 | ] |
| 312 | ); |
| 313 | ?> |
| 314 | </p> |
| 315 | </div> |
| 316 | |
| 317 | <?php |
| 318 | |
| 319 | // In case this is on plugin activation. |
| 320 | if ( isset( $_GET['activate'] ) ) { //phpcs:ignore |
| 321 | unset( $_GET['activate'] ); //phpcs:ignore |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Display admin notice and prevent plugin code execution, if the server is |
| 328 | * using old/insecure PHP version. |
| 329 | * |
| 330 | * @since 2.0.0 |
| 331 | */ |
| 332 | if ( version_compare( phpversion(), WPMS_PHP_VER, '<' ) ) { |
| 333 | add_action( 'admin_notices', 'wp_mail_smtp_insecure_php_version_notice' ); |
| 334 | |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * Display admin notice and prevent plugin code execution, if the WP version is lower than WPMS_WP_VER. |
| 340 | * |
| 341 | * @since 3.3.0 |
| 342 | */ |
| 343 | if ( version_compare( get_bloginfo( 'version' ), WPMS_WP_VER, '<' ) ) { |
| 344 | add_action( 'admin_notices', 'wp_mail_smtp_unsupported_wp_version_notice' ); |
| 345 | |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | require_once dirname( __FILE__ ) . '/wp-mail-smtp.php'; |
| 350 |