wp-mail-smtp
Last commit date
assets
8 years ago
languages
8 years ago
src
8 years ago
vendor
8 years ago
class-wpms-am-notification.php
8 years ago
readme.txt
8 years ago
wp-mail-smtp.php
8 years ago
wp_mail_smtp.php
8 years ago
wp_mail_smtp.php
857 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: WP Mail SMTP |
| 4 | * Version: 1.2.2 |
| 5 | * Plugin URI: https://wpforms.com/ |
| 6 | * Description: Reconfigures the wp_mail() function to use SMTP instead of mail() and creates an options page to manage the settings. |
| 7 | * Author: WPForms |
| 8 | * Author URI: https://wpforms.com/ |
| 9 | * Text Domain: wp-mail-smtp |
| 10 | * Domain Path: /languages |
| 11 | */ |
| 12 | |
| 13 | /** |
| 14 | * @author WPForms |
| 15 | * @copyright WPForms, 2007-17, All Rights Reserved |
| 16 | * This code is released under the GPL licence version 3 or later, available here |
| 17 | * http://www.gnu.org/licenses/gpl.txt |
| 18 | */ |
| 19 | |
| 20 | define( 'WPMS_PLUGIN_VER', '1.2.2' ); |
| 21 | define( 'WPMS_PHP_VER', '5.3' ); |
| 22 | |
| 23 | /** |
| 24 | * Setting options in wp-config.php |
| 25 | * |
| 26 | * Specifically aimed at WPMU users, you can set the options for this plugin as |
| 27 | * constants in wp-config.php. This disables the plugin's admin page and may |
| 28 | * improve performance very slightly. Copy the code below into wp-config.php. |
| 29 | */ |
| 30 | |
| 31 | /* |
| 32 | define('WPMS_ON', true); |
| 33 | define('WPMS_MAIL_FROM', 'From Email'); |
| 34 | define('WPMS_MAIL_FROM_NAME', 'From Name'); |
| 35 | define('WPMS_MAILER', 'smtp'); // Possible values 'smtp', 'mail', or 'sendmail' |
| 36 | define('WPMS_SET_RETURN_PATH', 'false'); // Sets $phpmailer->Sender if true |
| 37 | define('WPMS_SMTP_HOST', 'localhost'); // The SMTP mail host |
| 38 | define('WPMS_SMTP_PORT', 25); // The SMTP server port number |
| 39 | define('WPMS_SSL', ''); // Possible values '', 'ssl', 'tls' - note TLS is not STARTTLS |
| 40 | define('WPMS_SMTP_AUTH', true); // True turns on SMTP authentication, false turns it off |
| 41 | define('WPMS_SMTP_USER', 'username'); // SMTP authentication username, only used if WPMS_SMTP_AUTH is true |
| 42 | define('WPMS_SMTP_PASS', 'password'); // SMTP authentication password, only used if WPMS_SMTP_AUTH is true |
| 43 | */ |
| 44 | |
| 45 | /** |
| 46 | * Newer PHP version 5.3+ will be handled a lot differently, |
| 47 | * with better code and newer logic. |
| 48 | * |
| 49 | * @since 1.0.0 |
| 50 | */ |
| 51 | if ( version_compare( phpversion(), WPMS_PHP_VER, '>=' ) ) { |
| 52 | require_once dirname( __FILE__ ) . '/wp-mail-smtp.php'; |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Array of options and their default values. |
| 58 | * This is horrible, should be cleaned up at some point. |
| 59 | */ |
| 60 | global $wpms_options; |
| 61 | $wpms_options = array( |
| 62 | 'mail_from' => '', |
| 63 | 'mail_from_name' => '', |
| 64 | 'mailer' => 'smtp', |
| 65 | 'mail_set_return_path' => 'false', |
| 66 | 'smtp_host' => 'localhost', |
| 67 | 'smtp_port' => '25', |
| 68 | 'smtp_ssl' => 'none', |
| 69 | 'smtp_auth' => false, |
| 70 | 'smtp_user' => '', |
| 71 | 'smtp_pass' => '', |
| 72 | 'pepipost_user' => '', |
| 73 | 'pepipost_pass' => '', |
| 74 | 'pepipost_port' => '2525', |
| 75 | 'pepipost_ssl' => 'none', |
| 76 | 'wp_mail_smtp_am_notifications_hidden' => '', |
| 77 | ); |
| 78 | |
| 79 | /** |
| 80 | * Activation function. This function creates the required options and defaults. |
| 81 | */ |
| 82 | if ( ! function_exists( 'wp_mail_smtp_activate' ) ) : |
| 83 | /** |
| 84 | * What to do on plugin activation. |
| 85 | */ |
| 86 | function wp_mail_smtp_activate() { |
| 87 | |
| 88 | global $wpms_options; |
| 89 | |
| 90 | // Create the required options... |
| 91 | foreach ( $wpms_options as $name => $val ) { |
| 92 | add_option( $name, $val ); |
| 93 | } |
| 94 | } |
| 95 | endif; |
| 96 | |
| 97 | if ( ! function_exists( 'wp_mail_smtp_whitelist_options' ) ) : |
| 98 | /** |
| 99 | * Whitelist plugin options. |
| 100 | * |
| 101 | * @param array $whitelist_options |
| 102 | * |
| 103 | * @return mixed |
| 104 | */ |
| 105 | function wp_mail_smtp_whitelist_options( $whitelist_options ) { |
| 106 | |
| 107 | global $wpms_options; |
| 108 | |
| 109 | // Add our options to the array. |
| 110 | $whitelist_options['email'] = array_keys( $wpms_options ); |
| 111 | |
| 112 | return $whitelist_options; |
| 113 | } |
| 114 | endif; |
| 115 | |
| 116 | /** |
| 117 | * To avoid any (very unlikely) clashes, check if the function already exists. |
| 118 | */ |
| 119 | if ( ! function_exists( 'phpmailer_init_smtp' ) ) : |
| 120 | /** |
| 121 | * This code is copied, from wp-includes/pluggable.php as at version 2.2.2. |
| 122 | * |
| 123 | * @param PHPMailer $phpmailer It's passed by reference, so no need to return anything. |
| 124 | */ |
| 125 | function phpmailer_init_smtp( $phpmailer ) { |
| 126 | /* |
| 127 | * If constants are defined, apply them. |
| 128 | * We should have defined all required constants before using them. |
| 129 | */ |
| 130 | if ( |
| 131 | defined( 'WPMS_ON' ) && WPMS_ON && |
| 132 | defined( 'WPMS_MAILER' ) |
| 133 | ) { |
| 134 | $phpmailer->Mailer = WPMS_MAILER; |
| 135 | |
| 136 | if ( defined( 'WPMS_SET_RETURN_PATH' ) && WPMS_SET_RETURN_PATH ) { |
| 137 | $phpmailer->Sender = $phpmailer->From; |
| 138 | } |
| 139 | |
| 140 | if ( |
| 141 | WPMS_MAILER === 'smtp' && |
| 142 | defined( 'WPMS_SSL' ) && |
| 143 | defined( 'WPMS_SMTP_HOST' ) && |
| 144 | defined( 'WPMS_SMTP_PORT' ) |
| 145 | ) { |
| 146 | $phpmailer->SMTPSecure = WPMS_SSL; |
| 147 | $phpmailer->Host = WPMS_SMTP_HOST; |
| 148 | $phpmailer->Port = WPMS_SMTP_PORT; |
| 149 | |
| 150 | if ( |
| 151 | defined( 'WPMS_SMTP_AUTH' ) && WPMS_SMTP_AUTH && |
| 152 | defined( 'WPMS_SMTP_USER' ) && |
| 153 | defined( 'WPMS_SMTP_PASS' ) |
| 154 | ) { |
| 155 | $phpmailer->SMTPAuth = true; |
| 156 | $phpmailer->Username = WPMS_SMTP_USER; |
| 157 | $phpmailer->Password = WPMS_SMTP_PASS; |
| 158 | } |
| 159 | } |
| 160 | } else { |
| 161 | $option_mailer = get_option( 'mailer' ); |
| 162 | $option_smtp_host = get_option( 'smtp_host' ); |
| 163 | $option_smtp_ssl = get_option( 'smtp_ssl' ); |
| 164 | |
| 165 | // Check that mailer is not blank, and if mailer=smtp, host is not blank. |
| 166 | if ( |
| 167 | ! $option_mailer || |
| 168 | ( 'smtp' === $option_mailer && ! $option_smtp_host ) |
| 169 | ) { |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | // If the mailer is pepipost, make sure we have a username and password. |
| 174 | if ( 'pepipost' === $option_mailer && ( ! get_option( 'pepipost_user' ) && ! get_option( 'pepipost_pass' ) ) ) { |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | // Set the mailer type as per config above, this overrides the already called isMail method. |
| 179 | $phpmailer->Mailer = $option_mailer; |
| 180 | |
| 181 | // Set the Sender (return-path) if required. |
| 182 | if ( get_option( 'mail_set_return_path' ) ) { |
| 183 | $phpmailer->Sender = $phpmailer->From; |
| 184 | } |
| 185 | |
| 186 | // Set the SMTPSecure value, if set to none, leave this blank. |
| 187 | $phpmailer->SMTPSecure = $option_smtp_ssl; |
| 188 | if ( 'none' === $option_smtp_ssl ) { |
| 189 | $phpmailer->SMTPSecure = ''; |
| 190 | $phpmailer->SMTPAutoTLS = false; |
| 191 | } |
| 192 | |
| 193 | // If we're sending via SMTP, set the host. |
| 194 | if ( 'smtp' === $option_mailer ) { |
| 195 | // Set the other options. |
| 196 | $phpmailer->Host = $option_smtp_host; |
| 197 | $phpmailer->Port = get_option( 'smtp_port' ); |
| 198 | |
| 199 | // If we're using smtp auth, set the username & password. |
| 200 | if ( get_option( 'smtp_auth' ) === 'true' ) { |
| 201 | $phpmailer->SMTPAuth = true; |
| 202 | $phpmailer->Username = get_option( 'smtp_user' ); |
| 203 | $phpmailer->Password = get_option( 'smtp_pass' ); |
| 204 | } |
| 205 | } elseif ( 'pepipost' === $option_mailer ) { |
| 206 | // Set the Pepipost settings. |
| 207 | $phpmailer->Mailer = 'smtp'; |
| 208 | $phpmailer->Host = 'smtp.pepipost.com'; |
| 209 | $phpmailer->Port = get_option( 'pepipost_port' ); |
| 210 | $phpmailer->SMTPSecure = get_option( 'pepipost_ssl' ) === 'none' ? '' : get_option( 'pepipost_ssl' ); |
| 211 | $phpmailer->SMTPAuth = true; |
| 212 | $phpmailer->Username = get_option( 'pepipost_user' ); |
| 213 | $phpmailer->Password = get_option( 'pepipost_pass' ); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | // You can add your own options here, see the phpmailer documentation for more info: http://phpmailer.sourceforge.net/docs/. |
| 218 | /** @noinspection PhpUnusedLocalVariableInspection It's passed by reference. */ |
| 219 | $phpmailer = apply_filters( 'wp_mail_smtp_custom_options', $phpmailer ); |
| 220 | } |
| 221 | endif; |
| 222 | |
| 223 | if ( ! function_exists( 'wp_mail_smtp_options_page' ) ) : |
| 224 | /** |
| 225 | * This function outputs the plugin options page. |
| 226 | */ |
| 227 | function wp_mail_smtp_options_page() { |
| 228 | |
| 229 | global $phpmailer; |
| 230 | |
| 231 | // Make sure the PHPMailer class has been instantiated |
| 232 | // (copied verbatim from wp-includes/pluggable.php) |
| 233 | // (Re)create it, if it's gone missing. |
| 234 | if ( ! is_object( $phpmailer ) || ! is_a( $phpmailer, 'PHPMailer' ) ) { |
| 235 | require_once ABSPATH . WPINC . '/class-phpmailer.php'; |
| 236 | $phpmailer = new PHPMailer( true ); |
| 237 | } |
| 238 | |
| 239 | // Send a test mail if necessary. |
| 240 | if ( |
| 241 | isset( $_POST['wpms_action'] ) && |
| 242 | esc_html__( 'Send Test', 'wp-mail-smtp' ) === sanitize_text_field( $_POST['wpms_action'] ) && |
| 243 | is_email( $_POST['to'] ) |
| 244 | ) { |
| 245 | |
| 246 | check_admin_referer( 'test-email' ); |
| 247 | |
| 248 | // Set up the mail variables. |
| 249 | $to = sanitize_text_field( $_POST['to'] ); |
| 250 | /* translators: %s - email address where test mail will be sent to. */ |
| 251 | $subject = 'WP Mail SMTP: ' . sprintf( esc_html__( 'Test mail to %s', 'wp-mail-smtp' ), $to ); |
| 252 | $message = esc_html__( 'This is a test email generated by the WP Mail SMTP WordPress plugin.', 'wp-mail-smtp' ); |
| 253 | |
| 254 | // Set SMTPDebug level, default is 2 (commands + data + connection status). |
| 255 | $phpmailer->SMTPDebug = apply_filters( 'wp_mail_smtp_admin_test_email_smtp_debug', 2 ); |
| 256 | |
| 257 | // Start output buffering to grab smtp debugging output. |
| 258 | ob_start(); |
| 259 | |
| 260 | // Send the test mail. |
| 261 | $result = wp_mail( $to, $subject, $message ); |
| 262 | |
| 263 | // Grab the smtp debugging output. |
| 264 | $smtp_debug = ob_get_clean(); |
| 265 | |
| 266 | // Output the response. |
| 267 | ?> |
| 268 | <div id="message" class="updated notice is-dismissible"><p><strong><?php esc_html_e( 'Test Message Sent', 'wp-mail-smtp' ); ?></strong></p> |
| 269 | <p><?php esc_html_e( 'The result was:', 'wp-mail-smtp' ); ?></p> |
| 270 | <pre><?php var_dump( $result ); ?></pre> |
| 271 | |
| 272 | <p><?php esc_html_e( 'The full debugging output is shown below:', 'wp-mail-smtp' ); ?></p> |
| 273 | <pre><?php print_r( $phpmailer ); ?></pre> |
| 274 | |
| 275 | <p><?php esc_html_e( 'The SMTP debugging output is shown below:', 'wp-mail-smtp' ); ?></p> |
| 276 | <pre><?php echo $smtp_debug; ?></pre> |
| 277 | </div> |
| 278 | <?php |
| 279 | |
| 280 | // Destroy $phpmailer so it doesn't cause issues later. |
| 281 | unset( $phpmailer ); |
| 282 | } |
| 283 | |
| 284 | ?> |
| 285 | <div class="wrap"> |
| 286 | <h2> |
| 287 | <?php esc_html_e( 'WP Mail SMTP Settings', 'wp-mail-smtp' ); ?> |
| 288 | </h2> |
| 289 | |
| 290 | <form method="post" action="<?php echo admin_url( 'options.php' ); ?>"> |
| 291 | <?php wp_nonce_field( 'email-options' ); ?> |
| 292 | |
| 293 | <table class="form-table"> |
| 294 | <tr valign="top"> |
| 295 | <th scope="row"> |
| 296 | <label for="mail_from"><?php esc_html_e( 'From Email', 'wp-mail-smtp' ); ?></label> |
| 297 | </th> |
| 298 | <td> |
| 299 | <input name="mail_from" type="email" id="mail_from" value="<?php print( get_option( 'mail_from' ) ); ?>" size="40" class="regular-text"/> |
| 300 | |
| 301 | <p class="description"> |
| 302 | <?php |
| 303 | esc_html_e( 'You can specify the email address that emails should be sent from. If you leave this blank, the default email will be used.', 'wp-mail-smtp' ); |
| 304 | if ( get_option( 'db_version' ) < 6124 ) { |
| 305 | print( '<br /><span style="color: red;">' ); |
| 306 | _e( '<strong>Please Note:</strong> You appear to be using a version of WordPress prior to 2.3. Please ignore the From Name field and instead enter Name<email@domain.com> in this field.', 'wp-mail-smtp' ); |
| 307 | print( '</span>' ); |
| 308 | } |
| 309 | ?> |
| 310 | </p> |
| 311 | </td> |
| 312 | </tr> |
| 313 | <tr valign="top"> |
| 314 | <th scope="row"> |
| 315 | <label for="mail_from_name"><?php esc_html_e( 'From Name', 'wp-mail-smtp' ); ?></label> |
| 316 | </th> |
| 317 | <td> |
| 318 | <input name="mail_from_name" type="text" id="mail_from_name" value="<?php print( get_option( 'mail_from_name' ) ); ?>" size="40" class="regular-text"/> |
| 319 | |
| 320 | <p class="description"> |
| 321 | <?php esc_html_e( 'You can specify the name that emails should be sent from. If you leave this blank, the emails will be sent from WordPress.', 'wp-mail-smtp' ); ?> |
| 322 | </p> |
| 323 | </td> |
| 324 | </tr> |
| 325 | </table> |
| 326 | |
| 327 | <table class="form-table"> |
| 328 | <tr valign="top"> |
| 329 | <th scope="row"> |
| 330 | <?php esc_html_e( 'Mailer', 'wp-mail-smtp' ); ?> |
| 331 | </th> |
| 332 | <td> |
| 333 | <fieldset> |
| 334 | <legend class="screen-reader-text"> |
| 335 | <span><?php esc_html_e( 'Mailer', 'wp-mail-smtp' ); ?></span> |
| 336 | </legend> |
| 337 | |
| 338 | <p> |
| 339 | <input id="mailer_smtp" class="wpms_mailer" type="radio" name="mailer" value="smtp" <?php checked( 'smtp', get_option( 'mailer' ) ); ?> /> |
| 340 | <label for="mailer_smtp"><?php esc_html_e( 'Send all WordPress emails via SMTP.', 'wp-mail-smtp' ); ?></label> |
| 341 | </p> |
| 342 | <p> |
| 343 | <input id="mailer_mail" class="wpms_mailer" type="radio" name="mailer" value="mail" <?php checked( 'mail', get_option( 'mailer' ) ); ?> /> |
| 344 | <label for="mailer_mail"><?php esc_html_e( 'Use the PHP mail() function to send emails.', 'wp-mail-smtp' ); ?></label> |
| 345 | </p> |
| 346 | |
| 347 | <?php if ( wp_mail_smtp_is_pepipost_active() ) : ?> |
| 348 | <p> |
| 349 | <input id="mailer_pepipost" class="wpms_mailer" type="radio" name="mailer" value="pepipost" <?php checked( 'pepipost', get_option( 'mailer' ) ); ?> /> |
| 350 | <label for="mailer_pepipost"><?php esc_html_e( 'Use Pepipost SMTP to send emails.', 'wp-mail-smtp' ); ?></label> |
| 351 | </p> |
| 352 | <p class="description"> |
| 353 | <?php |
| 354 | printf( |
| 355 | /* translators: %1$s - link start; %2$s - link end. */ |
| 356 | esc_html__( 'Looking for high inbox delivery? Try Pepipost with easy setup and free emails. Learn more %1$shere%2$s.', 'wp-mail-smtp' ), |
| 357 | '<a href="https://app1.pepipost.com/index.php/login/wp_mail_smtp?page=signup&utm_source=WordPress&utm_campaign=Plugins&utm_medium=wp_mail_smtp&utm_term=organic&code=WP-MAIL-SMTP" target="_blank">', |
| 358 | '</a>' |
| 359 | ); |
| 360 | ?> |
| 361 | </p> |
| 362 | <?php endif; ?> |
| 363 | </fieldset> |
| 364 | </td> |
| 365 | </tr> |
| 366 | </table> |
| 367 | |
| 368 | <table class="form-table"> |
| 369 | <tr valign="top"> |
| 370 | <th scope="row"> |
| 371 | <?php esc_html_e( 'Return Path', 'wp-mail-smtp' ); ?> |
| 372 | </th> |
| 373 | <td> |
| 374 | <fieldset> |
| 375 | <legend class="screen-reader-text"> |
| 376 | <span><?php esc_html_e( 'Return Path', 'wp-mail-smtp' ); ?></span> |
| 377 | </legend> |
| 378 | |
| 379 | <label for="mail_set_return_path"> |
| 380 | <input name="mail_set_return_path" type="checkbox" id="mail_set_return_path" value="true" <?php checked( 'true', get_option( 'mail_set_return_path' ) ); ?> /> |
| 381 | <?php esc_html_e( 'Set the return-path to match the From Email', 'wp-mail-smtp' ); ?> |
| 382 | </label> |
| 383 | |
| 384 | <p class="description"> |
| 385 | <?php esc_html_e( 'Return Path indicates where non-delivery receipts - or bounce messages - are to be sent.', 'wp-mail-smtp' ); ?> |
| 386 | </p> |
| 387 | </fieldset> |
| 388 | </td> |
| 389 | </tr> |
| 390 | </table> |
| 391 | |
| 392 | <table class="form-table"> |
| 393 | <tr valign="top"> |
| 394 | <th scope="row"> |
| 395 | <?php _e( 'Hide Announcements', 'wp-mail-smtp' ); ?> |
| 396 | </th> |
| 397 | <td> |
| 398 | <fieldset> |
| 399 | <legend class="screen-reader-text"> |
| 400 | <span><?php _e( 'Hide Announcements', 'wp-mail-smtp' ); ?></span> |
| 401 | </legend> |
| 402 | |
| 403 | <label for="wp_mail_smtp_am_notifications_hidden"> |
| 404 | <input name="wp_mail_smtp_am_notifications_hidden" type="checkbox" id="wp_mail_smtp_am_notifications_hidden" value="true" <?php checked( 'true', get_option( 'wp_mail_smtp_am_notifications_hidden' ) ); ?> /> |
| 405 | <?php _e( 'Check this if you would like to hide plugin announcements and update details.', 'wp-mail-smtp' ); ?> |
| 406 | </label> |
| 407 | </fieldset> |
| 408 | </td> |
| 409 | </tr> |
| 410 | </table> |
| 411 | |
| 412 | <p class="submit"> |
| 413 | <input type="submit" name="submit" id="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'wp-mail-smtp' ); ?>"/> |
| 414 | </p> |
| 415 | |
| 416 | <div id="wpms_section_smtp" class="wpms_section"> |
| 417 | <h3> |
| 418 | <?php esc_html_e( 'SMTP Options', 'wp-mail-smtp' ); ?> |
| 419 | </h3> |
| 420 | <p><?php esc_html_e( 'These options only apply if you have chosen to send mail by SMTP above.', 'wp-mail-smtp' ); ?></p> |
| 421 | |
| 422 | <table class="form-table"> |
| 423 | <tr valign="top"> |
| 424 | <th scope="row"> |
| 425 | <label for="smtp_host"><?php esc_html_e( 'SMTP Host', 'wp-mail-smtp' ); ?></label> |
| 426 | </th> |
| 427 | <td> |
| 428 | <input name="smtp_host" type="text" id="smtp_host" value="<?php print( get_option( 'smtp_host' ) ); ?>" size="40" class="regular-text"/> |
| 429 | </td> |
| 430 | </tr> |
| 431 | <tr valign="top"> |
| 432 | <th scope="row"> |
| 433 | <label for="smtp_port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label> |
| 434 | </th> |
| 435 | <td> |
| 436 | <input name="smtp_port" type="text" id="smtp_port" value="<?php print( get_option( 'smtp_port' ) ); ?>" size="6" class="regular-text"/> |
| 437 | </td> |
| 438 | </tr> |
| 439 | <tr valign="top"> |
| 440 | <th scope="row"><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?> </th> |
| 441 | <td> |
| 442 | <fieldset> |
| 443 | <legend class="screen-reader-text"> |
| 444 | <span><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?></span> |
| 445 | </legend> |
| 446 | |
| 447 | <input id="smtp_ssl_none" type="radio" name="smtp_ssl" value="none" <?php checked( 'none', get_option( 'smtp_ssl' ) ); ?> /> |
| 448 | <label for="smtp_ssl_none"> |
| 449 | <span><?php esc_html_e( 'No encryption.', 'wp-mail-smtp' ); ?></span> |
| 450 | </label><br/> |
| 451 | |
| 452 | <input id="smtp_ssl_ssl" type="radio" name="smtp_ssl" value="ssl" <?php checked( 'ssl', get_option( 'smtp_ssl' ) ); ?> /> |
| 453 | <label for="smtp_ssl_ssl"> |
| 454 | <span><?php esc_html_e( 'Use SSL encryption.', 'wp-mail-smtp' ); ?></span> |
| 455 | </label><br/> |
| 456 | |
| 457 | <input id="smtp_ssl_tls" type="radio" name="smtp_ssl" value="tls" <?php checked( 'tls', get_option( 'smtp_ssl' ) ); ?> /> |
| 458 | <label for="smtp_ssl_tls"> |
| 459 | <span><?php esc_html_e( 'Use TLS encryption.', 'wp-mail-smtp' ); ?></span> |
| 460 | </label> |
| 461 | |
| 462 | <p class="description"><?php esc_html_e( 'TLS is not the same as STARTTLS. For most servers SSL is the recommended option.', 'wp-mail-smtp' ); ?></p> |
| 463 | </fieldset> |
| 464 | </td> |
| 465 | </tr> |
| 466 | <tr valign="top"> |
| 467 | <th scope="row"><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?> </th> |
| 468 | <td> |
| 469 | <fieldset> |
| 470 | <legend class="screen-reader-text"> |
| 471 | <span><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?></span> |
| 472 | </legend> |
| 473 | |
| 474 | <input id="smtp_auth_false" type="radio" name="smtp_auth" value="false" <?php checked( 'false', get_option( 'smtp_auth' ) ); ?> /> |
| 475 | <label for="smtp_auth_false"> |
| 476 | <span><?php esc_html_e( 'No: Do not use SMTP authentication.', 'wp-mail-smtp' ); ?></span> |
| 477 | </label><br/> |
| 478 | |
| 479 | <input id="smtp_auth_true" type="radio" name="smtp_auth" value="true" <?php checked( 'true', get_option( 'smtp_auth' ) ); ?> /> |
| 480 | <label for="smtp_auth_true"> |
| 481 | <span><?php esc_html_e( 'Yes: Use SMTP authentication.', 'wp-mail-smtp' ); ?></span> |
| 482 | </label><br/> |
| 483 | |
| 484 | <p class="description"> |
| 485 | <?php esc_html_e( 'If this is set to no, the values below are ignored.', 'wp-mail-smtp' ); ?> |
| 486 | </p> |
| 487 | </fieldset> |
| 488 | </td> |
| 489 | </tr> |
| 490 | <tr valign="top"> |
| 491 | <th scope="row"> |
| 492 | <label for="smtp_user"><?php esc_html_e( 'Username', 'wp-mail-smtp' ); ?></label> |
| 493 | </th> |
| 494 | <td> |
| 495 | <input name="smtp_user" type="text" id="smtp_user" value="<?php print( get_option( 'smtp_user' ) ); ?>" size="40" class="code" autocomplete="off"/> |
| 496 | </td> |
| 497 | </tr> |
| 498 | <tr valign="top"> |
| 499 | <th scope="row"> |
| 500 | <label for="smtp_pass"><?php esc_html_e( 'Password', 'wp-mail-smtp' ); ?></label> |
| 501 | </th> |
| 502 | <td> |
| 503 | <input name="smtp_pass" type="password" id="smtp_pass" value="<?php print( get_option( 'smtp_pass' ) ); ?>" size="40" class="code" autocomplete="off"/> |
| 504 | |
| 505 | <p class="description"> |
| 506 | <?php esc_html_e( 'This is in plain text because it must not be stored encrypted.', 'wp-mail-smtp' ); ?> |
| 507 | </p> |
| 508 | </td> |
| 509 | </tr> |
| 510 | </table> |
| 511 | |
| 512 | <p class="submit"> |
| 513 | <input type="submit" name="submit" id="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'wp-mail-smtp' ); ?>"/> |
| 514 | </p> |
| 515 | </div><!-- #wpms_section_smtp --> |
| 516 | |
| 517 | <?php if ( wp_mail_smtp_is_pepipost_active() ) : ?> |
| 518 | <div id="wpms_section_pepipost" class="wpms_section"> |
| 519 | <h3> |
| 520 | <?php esc_html_e( 'Pepipost SMTP Options', 'wp-mail-smtp' ); ?> |
| 521 | </h3> |
| 522 | <p> |
| 523 | <?php |
| 524 | printf( |
| 525 | /* translators: %s - Pepipost registration URL. */ |
| 526 | esc_html__( 'You need to signup on %s to get the SMTP username/password.', 'wp-mail-smtp' ), |
| 527 | '<a href="https://app1.pepipost.com/index.php/login/wp_mail_smtp?page=signup&utm_source=WordPress&utm_campaign=Plugins&utm_medium=wp_mail_smtp&utm_term=organic&code=WP-MAIL-SMTP" target="_blank">Pepipost</a>', |
| 528 | '' |
| 529 | ); |
| 530 | ?> |
| 531 | </p> |
| 532 | <table class="form-table"> |
| 533 | <tr valign="top"> |
| 534 | <th scope="row"> |
| 535 | <label for="pepipost_user"><?php esc_html_e( 'Username', 'wp-mail-smtp' ); ?></label> |
| 536 | </th> |
| 537 | <td> |
| 538 | <input name="pepipost_user" type="text" id="pepipost_user" value="<?php print( get_option( 'pepipost_user' ) ); ?>" size="40" class="code"/> |
| 539 | </td> |
| 540 | </tr> |
| 541 | <tr valign="top"> |
| 542 | <th scope="row"> |
| 543 | <label for="pepipost_pass"><?php esc_html_e( 'Password', 'wp-mail-smtp' ); ?></label> |
| 544 | </th> |
| 545 | <td> |
| 546 | <input name="pepipost_pass" type="text" id="pepipost_pass" value="<?php print( get_option( 'pepipost_pass' ) ); ?>" size="40" class="code"/> |
| 547 | </td> |
| 548 | </tr> |
| 549 | <tr valign="top"> |
| 550 | <th scope="row"> |
| 551 | <label for="pepipost_port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label> |
| 552 | </th> |
| 553 | <td> |
| 554 | <input name="pepipost_port" type="text" id="pepipost_port" value="<?php print( get_option( 'pepipost_port' ) ); ?>" size="6" class="regular-text"/> |
| 555 | </td> |
| 556 | </tr> |
| 557 | <tr valign="top"> |
| 558 | <th scope="row"> |
| 559 | <?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?> |
| 560 | </th> |
| 561 | <td> |
| 562 | <fieldset> |
| 563 | <legend class="screen-reader-text"> |
| 564 | <span> |
| 565 | <?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?> |
| 566 | </span> |
| 567 | </legend> |
| 568 | |
| 569 | <input id="pepipost_ssl_none" type="radio" name="pepipost_ssl" value="none" <?php checked( 'none', get_option( 'pepipost_ssl' ) ); ?> /> |
| 570 | <label for="pepipost_ssl_none"> |
| 571 | <span><?php esc_html_e( 'No encryption.', 'wp-mail-smtp' ); ?></span> |
| 572 | </label><br/> |
| 573 | |
| 574 | <input id="pepipost_ssl_ssl" type="radio" name="pepipost_ssl" value="ssl" <?php checked( 'ssl', get_option( 'pepipost_ssl' ) ); ?> /> |
| 575 | <label for="pepipost_ssl_ssl"> |
| 576 | <span><?php esc_html_e( 'Use SSL encryption.', 'wp-mail-smtp' ); ?></span> |
| 577 | </label><br/> |
| 578 | |
| 579 | <input id="pepipost_ssl_tls" type="radio" name="pepipost_ssl" value="tls" <?php checked( 'tls', get_option( 'pepipost_ssl' ) ); ?> /> |
| 580 | <label for="pepipost_ssl_tls"> |
| 581 | <span><?php esc_html_e( 'Use TLS encryption.', 'wp-mail-smtp' ); ?></span> |
| 582 | </label> |
| 583 | </fieldset> |
| 584 | </td> |
| 585 | </tr> |
| 586 | </table> |
| 587 | |
| 588 | <p class="submit"> |
| 589 | <input type="submit" name="submit" id="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'wp-mail-smtp' ); ?>"/> |
| 590 | </p> |
| 591 | </div><!-- #wpms_section_pepipost --> |
| 592 | <?php endif; ?> |
| 593 | |
| 594 | <input type="hidden" name="action" value="update"/> |
| 595 | <input type="hidden" name="option_page" value="email"> |
| 596 | </form> |
| 597 | |
| 598 | <h3><?php esc_html_e( 'Send a Test Email', 'wp-mail-smtp' ); ?></h3> |
| 599 | |
| 600 | <form method="POST" action=""> |
| 601 | <?php wp_nonce_field( 'test-email' ); ?> |
| 602 | |
| 603 | <table class="form-table"> |
| 604 | <tr valign="top"> |
| 605 | <th scope="row"> |
| 606 | <label for="to"><?php esc_html_e( 'To', 'wp-mail-smtp' ); ?></label> |
| 607 | </th> |
| 608 | <td> |
| 609 | <input name="to" type="email" id="to" value="" size="40" class="code"/> |
| 610 | <p class="description"><?php esc_html_e( 'Type an email address here and then click Send Test to generate a test email.', 'wp-mail-smtp' ); ?></p> |
| 611 | </td> |
| 612 | </tr> |
| 613 | </table> |
| 614 | |
| 615 | <p class="submit"> |
| 616 | <input type="submit" name="wpms_action" id="wpms_action" class="button-primary" value="<?php esc_attr_e( 'Send Test', 'wp-mail-smtp' ); ?>"/> |
| 617 | </p> |
| 618 | </form> |
| 619 | |
| 620 | <script type="text/javascript"> |
| 621 | /* globals jQuery */ |
| 622 | var wpmsOnMailerChange = function ( mailer ) { |
| 623 | // Hide all the mailer forms. |
| 624 | jQuery( '.wpms_section' ).hide(); |
| 625 | // Show the target mailer form. |
| 626 | jQuery( '#wpms_section_' + mailer ).show(); |
| 627 | }; |
| 628 | jQuery( document ).ready( function () { |
| 629 | // Call wpmsOnMailerChange() on startup with the current mailer. |
| 630 | wpmsOnMailerChange( jQuery( 'input.wpms_mailer:checked' ).val() ); |
| 631 | |
| 632 | // Watch the mailer for any changes |
| 633 | jQuery( 'input.wpms_mailer' ).on( 'change', function ( e ) { |
| 634 | // Call the wpmsOnMailerChange() handler, passing the value of the newly selected mailer. |
| 635 | wpmsOnMailerChange( jQuery( e.target ).val() ); |
| 636 | } ); |
| 637 | } ); |
| 638 | </script> |
| 639 | |
| 640 | </div> |
| 641 | <?php |
| 642 | } // End of wp_mail_smtp_options_page() function definition. |
| 643 | endif; |
| 644 | |
| 645 | if ( ! function_exists( 'wp_mail_smtp_menus' ) ) : |
| 646 | /** |
| 647 | * This function adds the required page (only 1 at the moment). |
| 648 | */ |
| 649 | function wp_mail_smtp_menus() { |
| 650 | |
| 651 | if ( function_exists( 'add_submenu_page' ) ) { |
| 652 | add_options_page( esc_html__( 'WP Mail SMTP Settings', 'wp-mail-smtp' ), esc_html__( 'WP Mail SMTP', 'wp-mail-smtp' ), 'manage_options', __FILE__, 'wp_mail_smtp_options_page' ); |
| 653 | } |
| 654 | } // End of wp_mail_smtp_menus() function definition. |
| 655 | endif; |
| 656 | |
| 657 | if ( ! function_exists( 'wp_mail_smtp_mail_from' ) ) : |
| 658 | /** |
| 659 | * This function sets the from email value. |
| 660 | * |
| 661 | * @param string $orig |
| 662 | * |
| 663 | * @return string |
| 664 | */ |
| 665 | function wp_mail_smtp_mail_from( $orig ) { |
| 666 | /* |
| 667 | * This is copied from pluggable.php lines 348-354 as at revision 10150 |
| 668 | * http://trac.wordpress.org/browser/branches/2.7/wp-includes/pluggable.php#L348. |
| 669 | */ |
| 670 | |
| 671 | // In case of CLI we don't have SERVER_NAME, so use host name instead, may be not a domain name. |
| 672 | $server_name = ! empty( $_SERVER['SERVER_NAME'] ) ? $_SERVER['SERVER_NAME'] : wp_parse_url( get_home_url( get_current_blog_id() ), PHP_URL_HOST ); |
| 673 | |
| 674 | // Get the site domain and get rid of www. |
| 675 | $sitename = strtolower( $server_name ); |
| 676 | if ( substr( $sitename, 0, 4 ) === 'www.' ) { |
| 677 | $sitename = substr( $sitename, 4 ); |
| 678 | } |
| 679 | |
| 680 | $default_from = 'wordpress@' . $sitename; |
| 681 | |
| 682 | /* |
| 683 | * End of copied code. |
| 684 | */ |
| 685 | |
| 686 | // If the from email is not the default, return it unchanged. |
| 687 | if ( $orig !== $default_from ) { |
| 688 | return $orig; |
| 689 | } |
| 690 | |
| 691 | if ( |
| 692 | defined( 'WPMS_ON' ) && WPMS_ON && |
| 693 | defined( 'WPMS_MAIL_FROM' ) |
| 694 | ) { |
| 695 | $mail_from_email = WPMS_MAIL_FROM; |
| 696 | |
| 697 | if ( ! empty( $mail_from_email ) ) { |
| 698 | return $mail_from_email; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | if ( is_email( get_option( 'mail_from' ), false ) ) { |
| 703 | return get_option( 'mail_from' ); |
| 704 | } |
| 705 | |
| 706 | // If in doubt, return the original value. |
| 707 | return $orig; |
| 708 | } // End of wp_mail_smtp_mail_from() function definition. |
| 709 | endif; |
| 710 | |
| 711 | if ( ! function_exists( 'wp_mail_smtp_mail_from_name' ) ) : |
| 712 | /** |
| 713 | * This function sets the from name value. |
| 714 | * |
| 715 | * @param string $orig |
| 716 | * |
| 717 | * @return string |
| 718 | */ |
| 719 | function wp_mail_smtp_mail_from_name( $orig ) { |
| 720 | |
| 721 | // Only filter if the from name is the default. |
| 722 | if ( 'WordPress' === $orig ) { |
| 723 | if ( |
| 724 | defined( 'WPMS_ON' ) && WPMS_ON && |
| 725 | defined( 'WPMS_MAIL_FROM_NAME' ) |
| 726 | ) { |
| 727 | $mail_from_name = WPMS_MAIL_FROM_NAME; |
| 728 | |
| 729 | if ( ! empty( $mail_from_name ) ) { |
| 730 | return $mail_from_name; |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | $from_name = get_option( 'mail_from_name' ); |
| 735 | if ( ! empty( $from_name ) && is_string( $from_name ) ) { |
| 736 | return $from_name; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | return $orig; |
| 741 | } |
| 742 | endif; |
| 743 | |
| 744 | /** |
| 745 | * Add a link to Settings page of a plugin on Plugins page. |
| 746 | * |
| 747 | * @param array $links |
| 748 | * @param string $file |
| 749 | * |
| 750 | * @return mixed |
| 751 | */ |
| 752 | function wp_mail_plugin_action_links( $links, $file ) { |
| 753 | |
| 754 | if ( plugin_basename( __FILE__ ) !== $file ) { |
| 755 | return $links; |
| 756 | } |
| 757 | |
| 758 | $settings_link = '<a href="options-general.php?page=' . plugin_basename( __FILE__ ) . '">' . esc_html__( 'Settings', 'wp-mail-smtp' ) . '</a>'; |
| 759 | |
| 760 | array_unshift( $links, $settings_link ); |
| 761 | |
| 762 | return $links; |
| 763 | } |
| 764 | |
| 765 | /** |
| 766 | * Awesome Motive Notifications. |
| 767 | * |
| 768 | * @since 0.11 |
| 769 | */ |
| 770 | function wp_mail_smtp_am_notifications() { |
| 771 | |
| 772 | $is_hidden = get_option( 'wp_mail_smtp_am_notifications_hidden', '' ); |
| 773 | |
| 774 | if ( 'true' === $is_hidden ) { |
| 775 | return; |
| 776 | } |
| 777 | |
| 778 | if ( ! class_exists( 'WPMS_AM_Notification' ) ) { |
| 779 | require_once dirname( __FILE__ ) . '/class-wpms-am-notification.php'; |
| 780 | } |
| 781 | |
| 782 | new WPMS_AM_Notification( 'smtp', WPMS_PLUGIN_VER ); |
| 783 | } |
| 784 | |
| 785 | add_action( 'plugins_loaded', 'wp_mail_smtp_am_notifications' ); |
| 786 | |
| 787 | /** |
| 788 | * Check whether the site is using Pepipost or not. |
| 789 | * |
| 790 | * @since 0.11 |
| 791 | * |
| 792 | * @return bool |
| 793 | */ |
| 794 | function wp_mail_smtp_is_pepipost_active() { |
| 795 | return apply_filters( 'wp_mail_smtp_options_is_pepipost_active', 'pepipost' === get_option( 'mailer' ) ); |
| 796 | } |
| 797 | |
| 798 | /** |
| 799 | * Check the current PHP version and display a notice if on unsupported PHP. |
| 800 | * |
| 801 | * @since 0.11 |
| 802 | */ |
| 803 | function wp_mail_smtp_check_php_version() { |
| 804 | |
| 805 | // Display for PHP below 5.3. |
| 806 | if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) { |
| 807 | return; |
| 808 | } |
| 809 | |
| 810 | // Display for admins only. |
| 811 | if ( ! is_super_admin() ) { |
| 812 | return; |
| 813 | } |
| 814 | |
| 815 | // Display on Dashboard page only. |
| 816 | if ( isset( $GLOBALS['pagenow'] ) && 'index.php' !== $GLOBALS['pagenow'] ) { |
| 817 | return; |
| 818 | } |
| 819 | |
| 820 | echo '<div class="notice notice-error">' . |
| 821 | '<p>' . |
| 822 | sprintf( |
| 823 | /* translators: %1$s - WP Mail SMTP plugin name; %2$s - opening a link tag; %3$s - closing a link tag. */ |
| 824 | esc_html__( |
| 825 | 'Your site is running an outdated version of PHP that is no longer supported and may cause issues with %1$s. %2$sRead more%3$s for additional information.', |
| 826 | 'wpforms' |
| 827 | ), |
| 828 | '<strong>WP Mail SMTP</strong>', |
| 829 | '<a href="https://wpforms.com/docs/supported-php-version/" target="_blank">', |
| 830 | '</a>' |
| 831 | ) . |
| 832 | '</p>' . |
| 833 | '</div>'; |
| 834 | } |
| 835 | |
| 836 | add_action( 'admin_notices', 'wp_mail_smtp_check_php_version' ); |
| 837 | |
| 838 | // Add an action on phpmailer_init. |
| 839 | add_action( 'phpmailer_init', 'phpmailer_init_smtp' ); |
| 840 | |
| 841 | if ( ! defined( 'WPMS_ON' ) || ! WPMS_ON ) { |
| 842 | // Whitelist our options. |
| 843 | add_filter( 'whitelist_options', 'wp_mail_smtp_whitelist_options' ); |
| 844 | // Add the create pages options. |
| 845 | add_action( 'admin_menu', 'wp_mail_smtp_menus' ); |
| 846 | // Add an activation hook for this plugin. |
| 847 | register_activation_hook( __FILE__, 'wp_mail_smtp_activate' ); |
| 848 | // Adds "Settings" link to the Plugins page. |
| 849 | add_filter( 'plugin_action_links', 'wp_mail_plugin_action_links', 10, 2 ); |
| 850 | } |
| 851 | |
| 852 | // Add filters to replace the mail from name and email address. |
| 853 | add_filter( 'wp_mail_from', 'wp_mail_smtp_mail_from' ); |
| 854 | add_filter( 'wp_mail_from_name', 'wp_mail_smtp_mail_from_name' ); |
| 855 | |
| 856 | load_plugin_textdomain( 'wp-mail-smtp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
| 857 |