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