Ei kuvausta

wp_mail_smtp.php 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. /**
  3. * Plugin Name: WP Mail SMTP
  4. * Version: 3.2.1
  5. * Requires at least: 4.9
  6. * Requires PHP: 5.6.20
  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: WPForms
  10. * Author URI: https://wpforms.com/
  11. * Network: false
  12. * Text Domain: wp-mail-smtp
  13. * Domain Path: /assets/languages
  14. */
  15. /**
  16. * @author WPForms
  17. * @copyright WPForms, 2007-21, All Rights Reserved
  18. * This code is released under the GPL licence version 3 or later, available here
  19. * https://www.gnu.org/licenses/gpl.txt
  20. */
  21. /**
  22. * Setting options in wp-config.php
  23. *
  24. * Specifically aimed at WP Multisite users, you can set the options for this plugin as
  25. * constants in wp-config.php. Copy the code below into wp-config.php and tweak settings.
  26. * Values from constants are NOT stripslash()'ed.
  27. *
  28. * When enabled, make sure to comment out (at the beginning of the line using //) those constants that you do not need,
  29. * or remove them completely, so they won't interfere with plugin settings.
  30. */
  31. /*
  32. define( 'WPMS_ON', true ); // True turns on the whole constants support and usage, false turns it off.
  33. define( 'WPMS_DO_NOT_SEND', true ); // Or false, in that case constant is ignored.
  34. define( 'WPMS_MAIL_FROM', 'mail@example.com' );
  35. define( 'WPMS_MAIL_FROM_FORCE', true ); // True turns it on, false turns it off.
  36. define( 'WPMS_MAIL_FROM_NAME', 'From Name' );
  37. define( 'WPMS_MAIL_FROM_NAME_FORCE', true ); // True turns it on, false turns it off.
  38. define( 'WPMS_MAILER', 'sendinblue' ); // Possible values: 'mail', 'smtpcom', 'sendinblue', 'mailgun', 'sendgrid', 'gmail', 'smtp'.
  39. define( 'WPMS_SET_RETURN_PATH', true ); // Sets $phpmailer->Sender if true, relevant only for Other SMTP mailer.
  40. // Recommended mailers.
  41. define( 'WPMS_SMTPCOM_API_KEY', '' );
  42. define( 'WPMS_SMTPCOM_CHANNEL', '' );
  43. define( 'WPMS_SENDINBLUE_API_KEY', '' );
  44. define( 'WPMS_SENDINBLUE_DOMAIN', '' );
  45. define( 'WPMS_ZOHO_DOMAIN', '' );
  46. define( 'WPMS_ZOHO_CLIENT_ID', '' );
  47. define( 'WPMS_ZOHO_CLIENT_SECRET', '' );
  48. define( 'WPMS_PEPIPOST_API_KEY', '' );
  49. define( 'WPMS_SENDINBLUE_API_KEY', '' );
  50. define( 'WPMS_MAILGUN_API_KEY', '' );
  51. define( 'WPMS_MAILGUN_DOMAIN', '' );
  52. define( 'WPMS_MAILGUN_REGION', 'US' ); // or 'EU' for Europe.
  53. define( 'WPMS_SENDGRID_API_KEY', '' );
  54. define( 'WPMS_GMAIL_CLIENT_ID', '' );
  55. define( 'WPMS_GMAIL_CLIENT_SECRET', '' );
  56. define( 'WPMS_SMTP_HOST', 'localhost' ); // The SMTP mail host.
  57. define( 'WPMS_SMTP_PORT', 25 ); // The SMTP server port number.
  58. define( 'WPMS_SSL', '' ); // Possible values '', 'ssl', 'tls' - note TLS is not STARTTLS.
  59. define( 'WPMS_SMTP_AUTH', true ); // True turns it on, false turns it off.
  60. define( 'WPMS_SMTP_USER', 'username' ); // SMTP authentication username, only used if WPMS_SMTP_AUTH is true.
  61. define( 'WPMS_SMTP_PASS', 'password' ); // SMTP authentication password, only used if WPMS_SMTP_AUTH is true.
  62. define( 'WPMS_SMTP_AUTOTLS', true ); // True turns it on, false turns it off.
  63. */
  64. /**
  65. * Don't allow multiple versions of 1.5.x (Lite and Pro) and above to be active.
  66. *
  67. * @since 1.5.0
  68. */
  69. if ( function_exists( 'wp_mail_smtp' ) ) {
  70. if ( ! function_exists( 'wp_mail_smtp_deactivate' ) ) {
  71. /**
  72. * Deactivate if plugin already activated.
  73. * Needed when transitioning from 1.5+ Lite to Pro.
  74. *
  75. * @since 1.5.0
  76. */
  77. function wp_mail_smtp_deactivate() {
  78. /*
  79. * Prevent issues of WP functions not being available for other plugins that hook into
  80. * this early deactivation. GH issue #861.
  81. */
  82. require_once ABSPATH . WPINC . '/pluggable.php';
  83. deactivate_plugins( plugin_basename( __FILE__ ) );
  84. }
  85. }
  86. add_action( 'admin_init', 'wp_mail_smtp_deactivate' );
  87. // Do not process the plugin code further.
  88. return;
  89. }
  90. if ( ! function_exists( 'wp_mail_smtp_check_pro_loading_allowed' ) ) {
  91. /**
  92. * Don't allow 1.4.x and below to break when 1.5+ Pro is activated.
  93. * This will stop the current plugin from loading and display a message in admin area.
  94. *
  95. * @since 1.5.0
  96. */
  97. function wp_mail_smtp_check_pro_loading_allowed() {
  98. // Check for pro without using wp_mail_smtp()->is_pro(), because at this point it's too early.
  99. if ( ! is_readable( rtrim( plugin_dir_path( __FILE__ ), '/\\' ) . '/src/Pro/Pro.php' ) ) {
  100. // Currently, not a pro version of the plugin is loaded.
  101. return false;
  102. }
  103. if ( ! function_exists( 'is_plugin_active' ) ) {
  104. require_once ABSPATH . '/wp-admin/includes/plugin.php';
  105. }
  106. // Search for old plugin name.
  107. if ( is_plugin_active( 'wp-mail-smtp/wp_mail_smtp.php' ) ) {
  108. /*
  109. * Prevent issues of WP functions not being available for other plugins that hook into
  110. * this early deactivation. GH issue #861.
  111. */
  112. require_once ABSPATH . WPINC . '/pluggable.php';
  113. // As Pro is loaded and Lite too - deactivate *silently* itself not to break older SMTP plugin.
  114. deactivate_plugins( plugin_basename( __FILE__ ) );
  115. add_action( 'admin_notices', 'wp_mail_smtp_lite_deactivation_notice' );
  116. return true;
  117. }
  118. return false;
  119. }
  120. if ( ! function_exists( 'wp_mail_smtp_lite_deactivation_notice' ) ) {
  121. /**
  122. * Display the notice after deactivation.
  123. *
  124. * @since 1.5.0
  125. */
  126. function wp_mail_smtp_lite_deactivation_notice() {
  127. 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>';
  128. if ( isset( $_GET['activate'] ) ) { // phpcs:ignore
  129. unset( $_GET['activate'] ); // phpcs:ignore
  130. }
  131. }
  132. }
  133. // Stop the plugin loading.
  134. if ( wp_mail_smtp_check_pro_loading_allowed() === true ) {
  135. return;
  136. }
  137. }
  138. if ( ! function_exists( 'wp_mail_smtp_insecure_php_version_notice' ) ) {
  139. /**
  140. * Display admin notice, if the server is using old/insecure PHP version.
  141. *
  142. * @since 2.0.0
  143. */
  144. function wp_mail_smtp_insecure_php_version_notice() {
  145. ?>
  146. <div class="notice notice-error">
  147. <p>
  148. <?php
  149. printf(
  150. wp_kses( /* translators: %1$s - WPBeginner URL for recommended WordPress hosting. */
  151. __( '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' ),
  152. array(
  153. 'a' => array(
  154. 'href' => array(),
  155. 'target' => array(),
  156. 'rel' => array(),
  157. ),
  158. 'strong' => array(),
  159. )
  160. ),
  161. 'https://www.wpbeginner.com/wordpress-hosting/'
  162. );
  163. ?>
  164. <br><br>
  165. <?php
  166. printf(
  167. wp_kses( /* translators: %s - WPMailSMTP.com docs URL with more details. */
  168. __( '<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' ),
  169. array(
  170. 'a' => array(
  171. 'href' => array(),
  172. 'target' => array(),
  173. 'rel' => array(),
  174. ),
  175. 'strong' => array(),
  176. )
  177. ),
  178. 'https://wpmailsmtp.com/docs/supported-php-versions-for-wp-mail-smtp/'
  179. );
  180. ?>
  181. </p>
  182. </div>
  183. <?php
  184. // In case this is on plugin activation.
  185. if ( isset( $_GET['activate'] ) ) { //phpcs:ignore
  186. unset( $_GET['activate'] ); //phpcs:ignore
  187. }
  188. }
  189. }
  190. if ( ! defined( 'WPMS_PLUGIN_VER' ) ) {
  191. define( 'WPMS_PLUGIN_VER', '3.2.1' );
  192. }
  193. if ( ! defined( 'WPMS_PHP_VER' ) ) {
  194. define( 'WPMS_PHP_VER', '5.6.20' );
  195. }
  196. if ( ! defined( 'WPMS_PLUGIN_FILE' ) ) {
  197. define( 'WPMS_PLUGIN_FILE', __FILE__ );
  198. }
  199. /**
  200. * Display admin notice and prevent plugin code execution, if the server is
  201. * using old/insecure PHP version.
  202. *
  203. * @since 2.0.0
  204. */
  205. if ( version_compare( phpversion(), WPMS_PHP_VER, '<' ) ) {
  206. add_action( 'admin_notices', 'wp_mail_smtp_insecure_php_version_notice' );
  207. return;
  208. }
  209. require_once dirname( __FILE__ ) . '/wp-mail-smtp.php';