Commit dbbcf6ac by Muhammad Usman

smtp plugin

parent 1dc3d19a
Pipeline #377 passed with stage
in 0 seconds
/* globals jQuery */
jQuery( document ).ready( function ( $ ) {
$( '.wp-mail-smtp-mailer input' ).click( function () {
if ( $( this ).prop( 'disabled' ) ) {
return false;
}
// Deselect the current mailer.
$( '.wp-mail-smtp-mailer' ).removeClass( 'active' );
// Select the correct one.
$( this ).parents( '.wp-mail-smtp-mailer' ).addClass( 'active' );
$( '.wp-mail-smtp-mailer-option' ).addClass( 'hidden' ).removeClass( 'active' );
$( '.wp-mail-smtp-mailer-option-' + $( this ).val() ).addClass( 'active' ).removeClass( 'hidden' );
} );
$( '.wp-mail-smtp-mailer-image' ).click( function () {
$( this ).parents( '.wp-mail-smtp-mailer' ).find( 'input' ).trigger( 'click' );
} );
$( '.wp-mail-smtp-setting-copy' ).click( function ( e ) {
e.preventDefault();
var target = $( '#' + $( this ).data( 'source_id' ) ).get(0);
target.select();
document.execCommand( 'Copy' );
} );
$( '#wp-mail-smtp-setting-smtp-auth' ).change( function() {
$( '#wp-mail-smtp-setting-row-smtp-user, #wp-mail-smtp-setting-row-smtp-pass' ).toggleClass( 'inactive' );
});
$( '#wp-mail-smtp-setting-row-smtp-encryption input').change( function() {
if ( 'tls' === $(this).val() ) {
$(' #wp-mail-smtp-setting-row-smtp-autotls' ).addClass( 'inactive' );
} else {
$( '#wp-mail-smtp-setting-row-smtp-autotls' ).removeClass( 'inactive' );
}
} );
} );
jQuery(document).ready(function(t){t(".wp-mail-smtp-mailer input").click(function(){if(t(this).prop("disabled"))return!1;t(".wp-mail-smtp-mailer").removeClass("active"),t(this).parents(".wp-mail-smtp-mailer").addClass("active"),t(".wp-mail-smtp-mailer-option").addClass("hidden").removeClass("active"),t(".wp-mail-smtp-mailer-option-"+t(this).val()).addClass("active").removeClass("hidden")}),t(".wp-mail-smtp-mailer-image").click(function(){t(this).parents(".wp-mail-smtp-mailer").find("input").trigger("click")}),t(".wp-mail-smtp-setting-copy").click(function(i){i.preventDefault(),t("#"+t(this).data("source_id")).get(0).select(),document.execCommand("Copy")}),t("#wp-mail-smtp-setting-smtp-auth").change(function(){t("#wp-mail-smtp-setting-row-smtp-user, #wp-mail-smtp-setting-row-smtp-pass").toggleClass("inactive")}),t("#wp-mail-smtp-setting-row-smtp-encryption input").change(function(){"tls"===t(this).val()?t(" #wp-mail-smtp-setting-row-smtp-autotls").addClass("inactive"):t("#wp-mail-smtp-setting-row-smtp-autotls").removeClass("inactive")})});
\ No newline at end of file
<?php
namespace WPMailSMTP\Admin;
/**
* Class PageAbstract.
*
* @since 1.0.0
*/
abstract class PageAbstract implements PageInterface {
/**
* @var string Slug of a tab.
*/
protected $slug;
/**
* @inheritdoc
*/
public function get_link() {
return esc_url(
add_query_arg(
'tab',
$this->slug,
admin_url( 'options-general.php?page=' . Area::SLUG )
)
);
}
/**
* Process tab form submission ($_POST ).
*
* @since 1.0.0
*
* @param array $data $_POST data specific for the plugin.
*/
public function process_post( $data ) {
}
/**
* Process tab & mailer specific Auth actions.
*
* @since 1.0.0
*/
public function process_auth() {
}
/**
* Print the nonce field for a specific tab.
*
* @since 1.0.0
*/
public function wp_nonce_field() {
wp_nonce_field( Area::SLUG . '-' . $this->slug );
}
/**
* Make sure that a user was referred from plugin admin page.
* To avoid security problems.
*
* @since 1.0.0
*/
public function check_admin_referer() {
check_admin_referer( Area::SLUG . '-' . $this->slug );
}
}
<?php
namespace WPMailSMTP\Admin;
/**
* Class PageInterface defines what should be in each page class.
*
* @since 1.0.0
*/
interface PageInterface {
/**
* URL to a tab.
*
* @since 1.0.0
*
* @return string
*/
public function get_link();
/**
* Title of a tab.
*
* @since 1.0.0
*
* @return string
*/
public function get_title();
/**
* Link label of a tab.
*
* @since 1.0.0
*
* @return string
*/
public function get_label();
/**
* Tab content.
*
* @since 1.0.0
*/
public function display();
}
<?php
namespace WPMailSMTP\Admin\Pages;
use WPMailSMTP\Options;
use WPMailSMTP\Providers\AuthAbstract;
/**
* Class Auth.
*
* @since 1.0.0
*/
class Auth {
/**
* @var string Slug of a tab.
*/
protected $slug = 'auth';
/**
* Launch mailer specific Auth logic.
*
* @since 1.0.0
*/
public function process_auth() {
$auth = wp_mail_smtp()->get_providers()->get_auth( Options::init()->get( 'mail', 'mailer' ) );
if ( $auth && $auth instanceof AuthAbstract ) {
$auth->process();
}
}
/**
* Return nothing, as we don't need this functionality.
*
* @since 1.0.0
*/
public function get_label() {
return '';
}
/**
* Return nothing, as we don't need this functionality.
*
* @since 1.0.0
*/
public function get_title() {
return '';
}
/**
* Do nothing, as we don't need this functionality.
*
* @since 1.0.0
*/
public function display() {
}
}
<?php
namespace WPMailSMTP\Admin\Pages;
use WPMailSMTP\Admin\PageAbstract;
use WPMailSMTP\Options;
use WPMailSMTP\WP;
/**
* Class Misc is part of Area, displays different plugin-related settings of the plugin (not related to emails).
*
* @since 1.0.0
*/
class Misc extends PageAbstract {
/**
* @var string Slug of a tab.
*/
protected $slug = 'misc';
/**
* @inheritdoc
*/
public function get_label() {
return esc_html__( 'Misc', 'wp-mail-smtp' );
}
/**
* @inheritdoc
*/
public function get_title() {
return $this->get_label();
}
/**
* @inheritdoc
*/
public function display() {
$options = new Options();
?>
<form method="POST" action="">
<?php $this->wp_nonce_field(); ?>
<!-- General Section Title -->
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading no-desc" id="wp-mail-smtp-setting-row-email-heading">
<div class="wp-mail-smtp-setting-field">
<h2><?php esc_html_e( 'General', 'wp-mail-smtp' ); ?></h2>
</div>
</div>
<!-- Hide Announcements -->
<div id="wp-mail-smtp-setting-row-am_notifications_hidden" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-am_notifications_hidden"><?php esc_html_e( 'Hide Announcements', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[general][am_notifications_hidden]" type="checkbox"
value="true" <?php checked( true, $options->get( 'general', 'am_notifications_hidden' ) ); ?>
id="wp-mail-smtp-setting-am_notifications_hidden"
/>
<label for="wp-mail-smtp-setting-am_notifications_hidden"><?php esc_html_e( 'Check this if you would like to hide plugin announcements and update details.', 'wp-mail-smtp' ); ?></label>
</div>
</div>
<p class="wp-mail-smtp-submit">
<button type="submit" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange"><?php esc_html_e( 'Save Settings', 'wp-mail-smtp' ); ?></button>
</p>
</form>
<?php
}
/**
* @inheritdoc
*/
public function process_post( $data ) {
$this->check_admin_referer();
$options = new Options();
// Unchecked checkbox doesn't exist in $_POST, so we need to ensure we actually have it.
if ( empty( $data['general']['am_notifications_hidden'] ) ) {
$data['general']['am_notifications_hidden'] = false;
}
$to_save = array_merge( $options->get_all(), $data );
// All the sanitization is done there.
$options->set( $to_save );
WP::add_admin_notice(
esc_html__( 'Settings were successfully saved.', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_SUCCESS
);
}
}
<?php
namespace WPMailSMTP\Admin\Pages;
use WPMailSMTP\Admin\PageAbstract;
use WPMailSMTP\Debug;
use WPMailSMTP\Options;
use WPMailSMTP\WP;
/**
* Class Settings is part of Area, displays general settings of the plugin.
*
* @since 1.0.0
*/
class Settings extends PageAbstract {
/**
* @var string Slug of a tab.
*/
protected $slug = 'settings';
/**
* @inheritdoc
*/
public function get_label() {
return esc_html__( 'Settings', 'wp-mail-smtp' );
}
/**
* @inheritdoc
*/
public function get_title() {
return $this->get_label();
}
/**
* @inheritdoc
*/
public function display() {
$options = new Options();
$mailer = $options->get( 'mail', 'mailer' );
?>
<form method="POST" action="">
<?php $this->wp_nonce_field(); ?>
<!-- Mail Section Title -->
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading no-desc" id="wp-mail-smtp-setting-row-email-heading">
<div class="wp-mail-smtp-setting-field">
<h2><?php esc_html_e( 'Mail', 'wp-mail-smtp' ); ?></h2>
</div>
</div>
<!-- From Email -->
<div id="wp-mail-smtp-setting-row-from_email" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-email wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-from_email"><?php esc_html_e( 'From Email', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[mail][from_email]" type="email"
value="<?php echo esc_attr( $options->get( 'mail', 'from_email' ) ); ?>"
<?php echo $options->is_const_defined( 'mail', 'from_email' ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_email" spellcheck="false"
/>
<p class="desc">
<?php esc_html_e( 'You can specify the email address that emails should be sent from.', 'wp-mail-smtp' ); ?><br/>
<?php
printf(
/* translators: %s - default email address. */
esc_html__( 'If you leave this blank, the default one will be used: %s.', 'wp-mail-smtp' ),
'<code>' . wp_mail_smtp()->get_processor()->get_default_email() . '</code>'
);
?>
</p>
<p class="desc">
<?php esc_html_e( 'Please note if you are sending using an email provider (Gmail, Yahoo, Hotmail, Outlook.com, etc) this setting should be your email address for that account.', 'wp-mail-smtp' ); ?>
</p>
</div>
</div>
<!-- From Name -->
<div id="wp-mail-smtp-setting-row-from_name" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-from_name"><?php esc_html_e( 'From Name', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[mail][from_name]" type="text"
value="<?php echo esc_attr( $options->get( 'mail', 'from_name' ) ); ?>"
<?php echo $options->is_const_defined( 'mail', 'from_name' ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_name" spellcheck="false"
/>
<p class="desc">
<?php esc_html_e( 'You can specify the name that emails should be sent from.', 'wp-mail-smtp' ); ?><br/>
<?php
printf(
/* translators: %s - WordPress. */
esc_html__( 'If you leave this blank, the emails will be sent from %s.', 'wp-mail-smtp' ),
'<code>WordPress</code>'
);
?>
</p>
</div>
</div>
<!-- Mailer -->
<div id="wp-mail-smtp-setting-row-mailer" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-mailer wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-mailer"><?php esc_html_e( 'Mailer', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<div class="wp-mail-smtp-mailers">
<?php foreach ( wp_mail_smtp()->get_providers()->get_options_all() as $provider ) : ?>
<div class="wp-mail-smtp-mailer <?php echo $mailer === $provider->get_slug() ? 'active' : ''; ?>">
<div class="wp-mail-smtp-mailer-image">
<img src="<?php echo esc_url( $provider->get_logo_url() ); ?>"
alt="<?php echo esc_attr( $provider->get_title() ); ?>">
</div>
<div class="wp-mail-smtp-mailer-text">
<input id="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>"
type="radio" name="wp-mail-smtp[mail][mailer]"
value="<?php echo esc_attr( $provider->get_slug() ); ?>"
<?php checked( $provider->get_slug(), $mailer ); ?>
<?php echo $options->is_const_defined( 'mail', 'mailer' ) ? 'disabled' : ''; ?>
/>
<label for="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>"><?php echo $provider->get_title(); ?></label>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<!-- Return Path -->
<div id="wp-mail-smtp-setting-row-return_path" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-return_path"><?php esc_html_e( 'Return Path', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[mail][return_path]" type="checkbox"
value="true" <?php checked( true, (bool) $options->get( 'mail', 'return_path' ) ); ?>
<?php echo $options->is_const_defined( 'mail', 'return_path' ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-return_path"
/>
<label for="wp-mail-smtp-setting-return_path">
<?php esc_html_e( 'Set the return-path to match the From Email', 'wp-mail-smtp' ); ?>
</label>
<p class="desc">
<?php esc_html_e( 'Return Path indicates where non-delivery receipts - or bounce messages - are to be sent.', 'wp-mail-smtp' ); ?><br/>
<?php esc_html_e( 'If unchecked bounce messages may be lost.', 'wp-mail-smtp' ); ?>
</p>
</div>
</div>
<!-- Mailer Options -->
<div class="wp-mail-smtp-mailer-options">
<?php foreach ( wp_mail_smtp()->get_providers()->get_options_all() as $provider ) : ?>
<div class="wp-mail-smtp-mailer-option wp-mail-smtp-mailer-option-<?php echo esc_attr( $provider->get_slug() ); ?> <?php echo $mailer === $provider->get_slug() ? 'active' : 'hidden'; ?>">
<!-- Mailer Option Title -->
<?php $provider_desc = $provider->get_description(); ?>
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading <?php echo empty( $provider_desc ) ? 'no-desc' : ''; ?>" id="wp-mail-smtp-setting-row-email-heading">
<div class="wp-mail-smtp-setting-field">
<h2><?php echo $provider->get_title(); ?></h2>
<?php if ( ! empty( $provider_desc ) ) : ?>
<p class="desc"><?php echo $provider_desc; ?></p>
<?php endif; ?>
</div>
</div>
<?php $provider->display_options(); ?>
</div>
<?php endforeach; ?>
</div>
<p class="wp-mail-smtp-submit">
<button type="submit" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange"><?php esc_html_e( 'Save Settings', 'wp-mail-smtp' ); ?></button>
</p>
</form>
<?php
}
/**
* @inheritdoc
*/
public function process_post( $data ) {
$this->check_admin_referer();
$options = new Options();
$old_opt = $options->get_all();
// When checkbox is unchecked - it's not submitted at all, so we need to define its default false value.
if ( ! isset( $data['mail']['return_path'] ) ) {
$data['mail']['return_path'] = false;
}
if ( ! isset( $data['smtp']['autotls'] ) ) {
$data['smtp']['autotls'] = false;
}
if ( ! isset( $data['smtp']['auth'] ) ) {
$data['smtp']['auth'] = false;
}
// Remove all debug messages when switching mailers.
if ( $old_opt['mail']['mailer'] !== $data['mail']['mailer'] ) {
Debug::clear();
}
$to_redirect = false;
// Old and new Gmail client id/secret values are different - we need to invalidate tokens and scroll to Auth button.
if (
$options->get( 'mail', 'mailer' ) === 'gmail' &&
(
$options->get( 'gmail', 'client_id' ) !== $data['gmail']['client_id'] ||
$options->get( 'gmail', 'client_secret' ) !== $data['gmail']['client_secret']
)
) {
unset( $old_opt['gmail'] );
if (
! empty( $data['gmail']['client_id'] ) &&
! empty( $data['gmail']['client_secret'] )
) {
$to_redirect = true;
}
}
// New gmail clients data will be added from new $data.
$to_save = Options::array_merge_recursive( $old_opt, $data );
// All the sanitization is done in Options class.
$options->set( $to_save );
if ( $to_redirect ) {
wp_redirect( $_POST['_wp_http_referer'] . '#wp-mail-smtp-setting-row-gmail-authorize' );
exit;
}
WP::add_admin_notice(
esc_html__( 'Settings were successfully saved.', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_SUCCESS
);
}
}
<?php
namespace WPMailSMTP\Admin\Pages;
use WPMailSMTP\Debug;
use WPMailSMTP\MailCatcher;
use WPMailSMTP\Options;
use WPMailSMTP\WP;
use WPMailSMTP\Admin\PageAbstract;
/**
* Class Test is part of Area, displays email testing page of the plugin.
*
* @since 1.0.0
*/
class Test extends PageAbstract {
/**
* @var string Slug of a tab.
*/
protected $slug = 'test';
/**
* @inheritdoc
*/
public function get_label() {
return esc_html__( 'Email Test', 'wp-mail-smtp' );
}
/**
* @inheritdoc
*/
public function get_title() {
return $this->get_label();
}
/**
* @inheritdoc
*/
public function display() {
?>
<form method="POST" action="">
<?php $this->wp_nonce_field(); ?>
<!-- Test Email Section Title -->
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading no-desc" id="wp-mail-smtp-setting-row-email-heading">
<div class="wp-mail-smtp-setting-field">
<h2><?php esc_html_e( 'Send a Test Email', 'wp-mail-smtp' ); ?></h2>
</div>
</div>
<!-- Test Email -->
<div id="wp-mail-smtp-setting-row-test_email" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-email wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-test_email"><?php esc_html_e( 'Send To', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[test_email]" type="email" id="wp-mail-smtp-setting-test_email" spellcheck="false" required />
<p class="desc">
<?php esc_html_e( 'Type an email address here and then click a button below to generate a test email.', 'wp-mail-smtp' ); ?>
</p>
</div>
</div>
<p class="wp-mail-smtp-submit">
<button type="submit" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange"><?php esc_html_e( 'Send Email', 'wp-mail-smtp' ); ?></button>
</p>
</form>
<?php
}
/**
* @inheritdoc
*/
public function process_post( $data ) {
$this->check_admin_referer();
if ( isset( $data['test_email'] ) ) {
$data['test_email'] = filter_var( $data['test_email'], FILTER_VALIDATE_EMAIL );
}
if ( empty( $data['test_email'] ) ) {
WP::add_admin_notice(
esc_html__( 'Test failed. Please use a valid email address and try to resend the test email.', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_WARNING
);
return;
}
global $phpmailer;
// Make sure the PHPMailer class has been instantiated.
if ( ! is_object( $phpmailer ) || ! is_a( $phpmailer, 'PHPMailer' ) ) {
require_once ABSPATH . WPINC . '/class-phpmailer.php';
$phpmailer = new MailCatcher( true );
}
// Set SMTPDebug level, default is 3 (commands + data + connection status).
$phpmailer->SMTPDebug = apply_filters( 'wp_mail_smtp_admin_test_email_smtp_debug', 3 );
// Start output buffering to grab smtp debugging output.
ob_start();
// Send the test mail.
$result = wp_mail(
$data['test_email'],
/* translators: %s - email address a test email will be sent to. */
'WP Mail SMTP: ' . sprintf( esc_html__( 'Test email to %s', 'wp-mail-smtp' ), $data['test_email'] ),
sprintf(
/* translators: %s - mailer name. */
esc_html__( 'This email was sent by %s mailer, and generated by the WP Mail SMTP WordPress plugin.', 'wp-mail-smtp' ),
wp_mail_smtp()->get_providers()->get_options( Options::init()->get( 'mail', 'mailer' ) )->get_title()
)
);
// Grab the smtp debugging output.
$smtp_debug = ob_get_clean();
/*
* Notify a user about the results.
*/
if ( $result ) {
WP::add_admin_notice(
esc_html__( 'Your email was sent successfully!', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_SUCCESS
);
} else {
$error = $this->get_debug_messages( $phpmailer, $smtp_debug );
WP::add_admin_notice(
'<p><strong>' . esc_html__( 'There was a problem while sending a test email. Related debugging output is shown below:', 'wp-mail-smtp' ) . '</strong></p>' .
'<blockquote style="border-left:1px solid orange;padding-left:10px">' . $error . '</blockquote>' .
'<p class="description">' . esc_html__( 'Please copy only the content of the error debug message above, identified with an orange left border, into the support forum topic if you experience any issues.', 'wp-mail-smtp' ) . '</p>',
WP::ADMIN_NOTICE_ERROR
);
}
}
/**
* Prepare debug information, that will help users to identify the error.
*
* @since 1.0.0
*
* @param MailCatcher $phpmailer
* @param string $smtp_debug
*
* @return string
*/
protected function get_debug_messages( $phpmailer, $smtp_debug ) {
$options = new Options();
/*
* Versions Debug.
*/
$versions_text = '<strong>Versions:</strong><br>';
$versions_text .= '<strong>WordPress:</strong> ' . get_bloginfo( 'version' ) . '<br>';
$versions_text .= '<strong>WordPress MS:</strong> ' . ( is_multisite() ? 'Yes' : 'No' ) . '<br>';
$versions_text .= '<strong>PHP:</strong> ' . PHP_VERSION . '<br>';
$versions_text .= '<strong>WP Mail SMTP:</strong> ' . WPMS_PLUGIN_VER . '<br>';
/*
* Mailer Debug.
*/
$mailer_text = '<strong>Params:</strong><br>';
$mailer_text .= '<strong>Mailer:</strong> ' . $options->get( 'mail', 'mailer' ) . '<br>';
$mailer_text .= '<strong>Constants:</strong> ' . ( $options->is_const_enabled() ? 'Yes' : 'No' ) . '<br>';
// Display different debug info based on the mailer.
$mailer = wp_mail_smtp()->get_providers()->get_mailer( $options->get( 'mail', 'mailer' ), $phpmailer );
if ( $mailer ) {
$mailer_text .= $mailer->get_debug_info();
}
/*
* General Debug.
*/
$debug_text = implode( '<br>', Debug::get() );
Debug::clear();
if ( ! empty( $debug_text ) ) {
$debug_text = '<br><strong>Debug:</strong><br>' . $debug_text . '<br>';
}
/*
* SMTP Debug.
*/
$smtp_text = '';
if ( $options->is_mailer_smtp() ) {
$smtp_text = '<strong>SMTP Debug:</strong><br>';
if ( ! empty( $smtp_debug ) ) {
$smtp_text .= esc_textarea( $smtp_debug );
} else {
$smtp_text .= '[empty]';
}
}
$errors = apply_filters( 'wp_mail_smtp_admin_test_get_debug_messages', array(
$versions_text,
$mailer_text,
$debug_text,
$smtp_text,
) );
return '<pre>' . implode( '<br>', array_filter( $errors ) ) . '</pre>';
}
}
<?php
namespace WPMailSMTP;
/**
* Class Core to handle all plugin initialization.
*
* @since 1.0.0
*/
class Core {
/**
* Without trailing slash.
*
* @var string
*/
public $plugin_url;
/**
* Without trailing slash.
*
* @var string
*/
public $plugin_path;
/**
* Core constructor.
*
* @since 1.0.0
*/
public function __construct() {
$this->plugin_url = rtrim( plugin_dir_url( __DIR__ ), '/\\' );
$this->plugin_path = rtrim( plugin_dir_path( __DIR__ ), '/\\' );
$this->hooks();
}
/**
* Assign all hooks to proper places.
*
* @since 1.0.0
*/
public function hooks() {
// Activation hook.
add_action( 'activate_wp-mail-smtp/wp_mail_smtp.php', array( $this, 'activate' ) );
add_action( 'plugins_loaded', array( $this, 'get_processor' ) );
add_action( 'plugins_loaded', array( $this, 'replace_phpmailer' ) );
add_action( 'plugins_loaded', array( $this, 'init_notifications' ) );
add_action( 'admin_notices', array( '\WPMailSMTP\WP', 'display_admin_notices' ) );
add_action( 'init', array( $this, 'init' ) );
}
/**
* Initial plugin actions.
*
* @since 1.0.0
*/
public function init() {
// Load translations just in case.
load_plugin_textdomain( 'wp-mail-smtp', false, plugin_basename( wp_mail_smtp()->plugin_path ) . '/languages' );
/*
* Constantly check in admin area, that we don't need to upgrade DB.
* Do not wait for the `admin_init` hook, because some actions are already done
* on `plugins_loaded`, so migration has to be done before.
*/
if ( WP::in_wp_admin() ) {
$this->get_migration();
$this->get_upgrade();
$this->get_admin();
}
}
/**
* Load the plugin core processor.
*
* @since 1.0.0
*
* @return Processor
*/
public function get_processor() {
static $processor;
if ( ! isset( $processor ) ) {
$processor = apply_filters( 'wp_mail_smtp_core_get_processor', new Processor() );
}
return $processor;
}
/**
* Load the plugin admin area.
*
* @since 1.0.0
*
* @return Admin\Area
*/
public function get_admin() {
static $admin;
if ( ! isset( $admin ) ) {
$admin = apply_filters( 'wp_mail_smtp_core_get_admin', new Admin\Area() );
}
return $admin;
}
/**
* Load the plugin providers loader.
*
* @since 1.0.0
*
* @return Providers\Loader
*/
public function get_providers() {
static $providers;
if ( ! isset( $providers ) ) {
$providers = apply_filters( 'wp_mail_smtp_core_get_providers', new Providers\Loader() );
}
return $providers;
}
/**
* Load the plugin option migrator.
*
* @since 1.0.0
*
* @return Migration
*/
public function get_migration() {
static $migration;
if ( ! isset( $migration ) ) {
$migration = apply_filters( 'wp_mail_smtp_core_get_migration', new Migration() );
}
return $migration;
}
/**
* Load the plugin upgrader.
*
* @since 1.1.0
*
* @return Upgrade
*/
public function get_upgrade() {
static $upgrade;
if ( ! isset( $upgrade ) ) {
$upgrade = apply_filters( 'wp_mail_smtp_core_get_upgrade', new Upgrade() );
}
return $upgrade;
}
/**
* Awesome Motive Notifications.
*
* @since 1.0.0
*/
public function init_notifications() {
if ( Options::init()->get( 'general', 'am_notifications_hidden' ) ) {
return;
}
static $notification;
if ( ! isset( $notification ) ) {
$notification = new AM_Notification( 'smtp', WPMS_PLUGIN_VER );
}
}
/**
* Init the \PHPMailer replacement.
*
* @since 1.0.0
*
* @return \WPMailSMTP\MailCatcher
*/
public function replace_phpmailer() {
global $phpmailer;
return $this->replace_w_fake_phpmailer( $phpmailer );
}
/**
* Overwrite default PhpMailer with out MailCatcher.
*
* @since 1.0.0
*
* @param null $obj
*
* @return \WPMailSMTP\MailCatcher
*/
protected function replace_w_fake_phpmailer( &$obj = null ) {
$obj = new MailCatcher();
return $obj;
}
/**
* What to do on plugin activation.
*
* @since 1.0.0
*/
public function activate() {
// Store the plugin version activated to reference with upgrades.
update_option( 'wp_mail_smtp_version', WPMS_PLUGIN_VER );
// Create and store initial plugin settings.
$options = array(
'mail' => array(
'from_email' => get_option( 'admin_email' ),
'from_name' => get_bloginfo( 'name' ),
'mailer' => 'mail',
'return_path' => false,
),
'smtp' => array(
'autotls' => true,
),
);
Options::init()->set( $options, true );
}
}
<?php
namespace WPMailSMTP;
/**
* Class Debug that will save all errors or warnings generated by APIs or SMTP
* and display in area for administrators.
*
* Usage example:
* Debug::set( 'Some warning: %s', array( '%s' => $e->getMessage() );
* $debug = Debug::get(); // array
* $debug = Debug::get_last(); // string
*
* @since 1.2.0
*/
class Debug {
/**
* Key for options table where all messages will be saved to.
*/
const OPTION_KEY = 'wp_mail_smtp_debug';
/**
* Save the debug message to a debug log.
* Adds one more to a list, at the end.
*
* @since 1.2.0
*
* @param string $message
*/
public static function set( $message ) {
if ( ! is_string( $message ) ) {
$message = \json_encode( $message );
}
$message = wp_strip_all_tags( $message, false );
$all = self::get();
array_push( $all, $message );
update_option( self::OPTION_KEY, $all, false );
}
/**
* Remove all messages for a debug log.
*
* @since 1.2.0
*/
public static function clear() {
update_option( self::OPTION_KEY, array(), false );
}
/**
* Retrieve all messages from a debug log.
*
* @since 1.2.0
*
* @return array
*/
public static function get() {
$all = get_option( self::OPTION_KEY, array() );
if ( ! is_array( $all ) ) {
$all = (array) $all;
}
return $all;
}
/**
* Get the last message that was saved to a debug log.
*
* @since 1.2.0
*
* @return string
*/
public static function get_last() {
$all = self::get();
if ( ! empty( $all ) && is_array( $all ) ) {
return (string) $all[ count( $all ) - 1 ];
}
return '';
}
/**
* Get the proper variable content output to debug.
*
* @since 1.2.0
*
* @param mixed $var
*
* @return string
*/
public static function pvar( $var = '' ) {
ob_start();
echo '<code>';
if ( is_bool( $var ) || empty( $var ) ) {
var_dump( $var );
} else {
print_r( $var );
}
echo '</code>';
$output = ob_get_clean();
return str_replace( array( "\r\n", "\r", "\n" ), '', $output );
}
}
<?php
namespace WPMailSMTP;
// Load PHPMailer class, so we can subclass it.
if ( ! class_exists( 'PHPMailer', false ) ) {
require_once ABSPATH . WPINC . '/class-phpmailer.php';
}
/**
* Class MailCatcher replaces the \PHPMailer and modifies the email sending logic.
* Thus, we can use other mailers API to do what we need, or stop emails completely.
*
* @since 1.0.0
*/
class MailCatcher extends \PHPMailer {
/**
* Modify the default send() behaviour.
* For those mailers, that relies on PHPMailer class - call it directly.
* For others - init the correct provider and process it.
*
* @since 1.0.0
*
* @throws \phpmailerException Throws when sending via PhpMailer fails for some reason.
*
* @return bool
*/
public function send() {
$options = new Options();
$mail_mailer = $options->get( 'mail', 'mailer' );
// Define a custom header, that will be used in Gmail/SMTP mailers.
$this->XMailer = 'WPMailSMTP/Mailer/' . $mail_mailer . ' ' . WPMS_PLUGIN_VER;
// Use the default PHPMailer, as we inject our settings there for certain providers.
if (
$mail_mailer === 'mail' ||
$mail_mailer === 'smtp' ||
$mail_mailer === 'pepipost'
) {
return parent::send();
}
// We need this so that the \PHPMailer class will correctly prepare all the headers.
$this->Mailer = 'mail';
// Prepare everything (including the message) for sending.
if ( ! $this->preSend() ) {
return false;
}
$mailer = wp_mail_smtp()->get_providers()->get_mailer( $mail_mailer, $this );
if ( ! $mailer ) {
return false;
}
if ( ! $mailer->is_php_compatible() ) {
return false;
}
/*
* Send the actual email.
* We reuse everything, that was preprocessed for usage in \PHPMailer.
*/
$mailer->send();
return $mailer->is_email_sent();
}
}
<?php
namespace WPMailSMTP;
/**
* Class Migration helps migrate all plugin options saved into DB to a new storage location.
*
* @since 1.0.0
*/
class Migration {
/**
* All old values for pre 1.0 version of a plugin.
*
* @var array
*/
protected $old_keys = array(
'pepipost_ssl',
'pepipost_port',
'pepipost_pass',
'pepipost_user',
'smtp_pass',
'smtp_user',
'smtp_auth',
'smtp_ssl',
'smtp_port',
'smtp_host',
'mail_set_return_path',
'mailer',
'mail_from_name',
'mail_from',
'wp_mail_smtp_am_notifications_hidden',
);
/**
* Old values, taken from $old_keys options.
*
* @var array
*/
protected $old_values = array();
/**
* Converted array of data from previous option values.
*
* @var array
*/
protected $new_values = array();
/**
* Migration constructor.
*
* @since 1.0.0
*/
public function __construct() {
if ( $this->is_migrated() ) {
return;
}
$this->old_values = $this->get_old_values();
$this->new_values = $this->get_converted_options();
Options::init()->set( $this->new_values );
// Removing all options will be enabled some time in the future.
// $this->clean_deprecated_data();
}
/**
* Whether we already migrated or not.
*
* @since 1.0.0
*
* @return bool
*/
protected function is_migrated() {
$is_migrated = false;
$new_values = get_option( Options::META_KEY, array() );
if ( ! empty( $new_values ) ) {
$is_migrated = true;
}
return $is_migrated;
}
/**
* Get all old values from DB.
*
* @since 1.0.0
*
* @return array
*/
protected function get_old_values() {
$old_values = array();
foreach ( $this->old_keys as $old_key ) {
$old_values[ $old_key ] = get_option( $old_key, '' );
}
return $old_values;
}
/**
* Convert old values from key=>value to a multidimensional array of data.
*
* @since 1.0.0
*/
protected function get_converted_options() {
$converted = array();
foreach ( $this->old_keys as $old_key ) {
switch ( $old_key ) {
case 'pepipost_user':
case 'pepipost_pass':
case 'pepipost_port':
case 'pepipost_ssl':
// Do not migrate pepipost options if it's not activated at the moment.
if ( 'pepipost' === $this->old_values['mailer'] ) {
$shortcut = explode( '_', $old_key );
if ( $old_key === 'pepipost_ssl' ) {
$converted[ $shortcut[0] ]['encryption'] = $this->old_values[ $old_key ];
} else {
$converted[ $shortcut[0] ][ $shortcut[1] ] = $this->old_values[ $old_key ];
}
}
break;
case 'smtp_host':
case 'smtp_port':
case 'smtp_ssl':
case 'smtp_auth':
case 'smtp_user':
case 'smtp_pass':
$shortcut = explode( '_', $old_key );
if ( $old_key === 'smtp_ssl' ) {
$converted[ $shortcut[0] ]['encryption'] = $this->old_values[ $old_key ];
} elseif ( $old_key === 'smtp_auth' ) {
$converted[ $shortcut[0] ][ $shortcut[1] ] = ( $this->old_values[ $old_key ] === 'true' ? 'yes' : 'no' );
} else {
$converted[ $shortcut[0] ][ $shortcut[1] ] = $this->old_values[ $old_key ];
}
break;
case 'mail_from':
$converted['mail']['from_email'] = $this->old_values[ $old_key ];
break;
case 'mail_from_name':
$converted['mail']['from_name'] = $this->old_values[ $old_key ];
break;
case 'mail_set_return_path':
$converted['mail']['return_path'] = ( $this->old_values[ $old_key ] === 'true' );
break;
case 'mailer':
$converted['mail']['mailer'] = $this->old_values[ $old_key ];
break;
case 'wp_mail_smtp_am_notifications_hidden':
$converted['general']['am_notifications_hidden'] = ( $this->old_values[ $old_key ] === 'true' );
break;
}
}
$converted = $this->get_converted_constants_options( $converted );
return $converted;
}
/**
* Some users use constants in wp-config.php to define values.
* We need to prioritize them and reapply data to options.
* Use only those that are actually defined.
*
* @since 1.0.0
*
* @param array $converted
*
* @return array
*/
protected function get_converted_constants_options( $converted ) {
// Are we configured via constants?
if ( ! defined( 'WPMS_ON' ) || ! WPMS_ON ) {
return $converted;
}
/*
* Mail settings.
*/
if ( defined( 'WPMS_MAIL_FROM' ) ) {
$converted['mail']['from_email'] = WPMS_MAIL_FROM;
}
if ( defined( 'WPMS_MAIL_FROM_NAME' ) ) {
$converted['mail']['from_name'] = WPMS_MAIL_FROM_NAME;
}
if ( defined( 'WPMS_MAILER' ) ) {
$converted['mail']['return_path'] = WPMS_MAILER;
}
if ( defined( 'WPMS_SET_RETURN_PATH' ) ) {
$converted['mail']['mailer'] = WPMS_SET_RETURN_PATH;
}
/*
* SMTP settings.
*/
if ( defined( 'WPMS_SMTP_HOST' ) ) {
$converted['smtp']['host'] = WPMS_SMTP_HOST;
}
if ( defined( 'WPMS_SMTP_PORT' ) ) {
$converted['smtp']['port'] = WPMS_SMTP_PORT;
}
if ( defined( 'WPMS_SSL' ) ) {
$converted['smtp']['ssl'] = WPMS_SSL;
}
if ( defined( 'WPMS_SMTP_AUTH' ) ) {
$converted['smtp']['auth'] = WPMS_SMTP_AUTH;
}
if ( defined( 'WPMS_SMTP_USER' ) ) {
$converted['smtp']['user'] = WPMS_SMTP_USER;
}
if ( defined( 'WPMS_SMTP_PASS' ) ) {
$converted['smtp']['pass'] = WPMS_SMTP_PASS;
}
return $converted;
}
/**
* Delete all old values that are stored separately each.
*
* @since 1.0.0
*/
protected function clean_deprecated_data() {
foreach ( $this->old_keys as $old_key ) {
delete_option( $old_key );
}
}
}
<?php
namespace WPMailSMTP;
/**
* Class Processor modifies the behaviour of wp_mail() function.
*
* @since 1.0.0
*/
class Processor {
/**
* Processor constructor.
*
* @since 1.0.0
*/
public function __construct() {
$this->hooks();
}
/**
* Assign all hooks to proper places.
*
* @since 1.0.0
*/
public function hooks() {
add_action( 'phpmailer_init', array( $this, 'phpmailer_init' ) );
add_filter( 'wp_mail_from', array( $this, 'filter_mail_from_email' ) );
add_filter( 'wp_mail_from_name', array( $this, 'filter_mail_from_name' ), 11 );
}
/**
* Redefine certain PHPMailer options with our custom ones.
*
* @since 1.0.0
*
* @param \PHPMailer $phpmailer It's passed by reference, so no need to return anything.
*/
public function phpmailer_init( $phpmailer ) {
$options = new Options();
$mailer = $options->get( 'mail', 'mailer' );
// Check that mailer is not blank, and if mailer=smtp, host is not blank.
if (
! $mailer ||
( 'smtp' === $mailer && ! $options->get( 'smtp', 'host' ) )
) {
return;
}
// If the mailer is pepipost, make sure we have a username and password.
if (
'pepipost' === $mailer &&
( ! $options->get( 'pepipost', 'user' ) && ! $options->get( 'pepipost', 'pass' ) )
) {
return;
}
// Set the mailer type as per config above, this overrides the already called isMail method.
// It's basically always 'smtp'.
$phpmailer->Mailer = $mailer;
// Set the Sender (return-path) if required.
if ( $options->get( 'mail', 'return_path' ) ) {
$phpmailer->Sender = $phpmailer->From;
}
// Set the SMTPSecure value, if set to none, leave this blank. Possible values: 'ssl', 'tls', ''.
if ( 'none' === $options->get( $mailer, 'encryption' ) ) {
$phpmailer->SMTPSecure = '';
} else {
$phpmailer->SMTPSecure = $options->get( $mailer, 'encryption' );
}
// Check if user has disabled SMTPAutoTLS.
if ( $options->get( $mailer, 'encryption' ) !== 'tls' && ! $options->get( $mailer, 'autotls' ) ) {
$phpmailer->SMTPAutoTLS = false;
}
// If we're sending via SMTP, set the host.
if ( 'smtp' === $mailer ) {
// Set the other options.
$phpmailer->Host = $options->get( $mailer, 'host' );
$phpmailer->Port = $options->get( $mailer, 'port' );
// If we're using smtp auth, set the username & password.
if ( $options->get( $mailer, 'auth' ) ) {
$phpmailer->SMTPAuth = true;
$phpmailer->Username = $options->get( $mailer, 'user' );
$phpmailer->Password = $options->get( $mailer, 'pass' );
}
} elseif ( 'pepipost' === $mailer ) {
// Set the Pepipost settings for BC.
$phpmailer->Mailer = 'smtp';
$phpmailer->Host = 'smtp.pepipost.com';
$phpmailer->Port = $options->get( $mailer, 'port' );
$phpmailer->SMTPSecure = $options->get( $mailer, 'encryption' ) === 'none' ? '' : $options->get( $mailer, 'encryption' );
$phpmailer->SMTPAuth = true;
$phpmailer->Username = $options->get( $mailer, 'user' );
$phpmailer->Password = $options->get( $mailer, 'pass' );
}
// You can add your own options here.
// See the phpmailer documentation for more info: https://github.com/PHPMailer/PHPMailer/tree/5.2-stable.
/** @noinspection PhpUnusedLocalVariableInspection It's passed by reference. */
$phpmailer = apply_filters( 'wp_mail_smtp_custom_options', $phpmailer );
}
/**
* Modify the email address that is used for sending emails.
*
* @since 1.0.0
*
* @param string $email
*
* @return string
*/
public function filter_mail_from_email( $email ) {
// If the from email is not the default, return it unchanged.
if ( $email !== $this->get_default_email() ) {
return $email;
}
$from_email = Options::init()->get( 'mail', 'from_email' );
if ( ! empty( $from_email ) ) {
return $from_email;
}
return $email;
}
/**
* Modify the sender name that is used for sending emails.
*
* @since 1.0.0
*
* @param string $name
*
* @return string
*/
public function filter_mail_from_name( $name ) {
if ( 'WordPress' === $name ) {
$name = Options::init()->get( 'mail', 'from_name' );
}
return $name;
}
/**
* Get the default email address based on domain name.
*
* @since 1.0.0
*
* @return string
*/
public function get_default_email() {
// In case of CLI we don't have SERVER_NAME, so use host name instead, may be not a domain name.
$server_name = ! empty( $_SERVER['SERVER_NAME'] ) ? $_SERVER['SERVER_NAME'] : wp_parse_url( get_home_url( get_current_blog_id() ), PHP_URL_HOST );
// Get the site domain and get rid of www.
$sitename = strtolower( $server_name );
if ( substr( $sitename, 0, 4 ) === 'www.' ) {
$sitename = substr( $sitename, 4 );
}
return 'wordpress@' . $sitename;
}
}
<?php
namespace WPMailSMTP\Providers;
/**
* Class AuthAbstract.
*
* @since 1.0.0
*/
abstract class AuthAbstract implements AuthInterface {
/**
* Get the url, that users will be redirected back to finish the OAuth process.
*
* @since 1.0.0
*
* @return string
*/
public static function get_plugin_auth_url() {
return add_query_arg( 'tab', 'auth', wp_mail_smtp()->get_admin()->get_admin_page_url() );
}
}
<?php
namespace WPMailSMTP\Providers;
/**
* Interface AuthInterface.
*
* @since 1.0.0
*/
interface AuthInterface {
/**
* Do something for this Auth implementation.
*
* @since 1.0.0
*/
public function process();
}
<?php
namespace WPMailSMTP\Providers\Gmail;
use WPMailSMTP\Debug;
use WPMailSMTP\Options as PluginOptions;
use WPMailSMTP\Providers\AuthAbstract;
/**
* Class Auth to request access and refresh tokens.
*
* @since 1.0.0
*/
class Auth extends AuthAbstract {
/**
* Gmail options.
*
* @var array
*/
private $gmail;
/**
* @var \Google_Client
*/
private $client;
/**
* @var string
*/
private $mailer;
/**
* Auth constructor.
*
* @since 1.0.0
*/
public function __construct() {
$options = new PluginOptions();
$this->mailer = $options->get( 'mail', 'mailer' );
if ( $this->mailer !== 'gmail' ) {
return;
}
$this->gmail = $options->get_group( $this->mailer );
if ( $this->is_clients_saved() ) {
$this->include_google_lib();
$this->client = $this->get_client();
}
}
/**
* Use the composer autoloader to include the Google Library and all its dependencies.
*
* @since 1.0.0
*/
protected function include_google_lib() {
require wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
}
/**
* Init and get the Google Client object.
*
* @since 1.0.0
*/
public function get_client() {
// Doesn't load client twice + gives ability to overwrite.
if ( ! empty( $this->client ) ) {
return $this->client;
}
$client = new \Google_Client(
array(
'client_id' => $this->gmail['client_id'],
'client_secret' => $this->gmail['client_secret'],
'redirect_uris' => array(
Auth::get_plugin_auth_url(),
),
)
);
$client->setAccessType( 'offline' );
$client->setApprovalPrompt( 'force' );
$client->setIncludeGrantedScopes( true );
// We request only the sending capability, as it's what we only need to do.
$client->setScopes( array( \Google_Service_Gmail::GMAIL_SEND ) );
$client->setRedirectUri( self::get_plugin_auth_url() );
if (
empty( $this->gmail['access_token'] ) &&
! empty( $this->gmail['auth_code'] )
) {
try {
$creds = $client->fetchAccessTokenWithAuthCode( $this->gmail['auth_code'] );
} catch ( \Exception $e ) {
$creds['error'] = $e->getMessage();
Debug::set( $e->getMessage() );
}
// Bail if we have an error.
if ( ! empty( $creds['error'] ) ) {
// TODO: save this error to display to a user later.
return $client;
}
$this->update_access_token( $client->getAccessToken() );
$this->update_refresh_token( $client->getRefreshToken() );
}
if ( ! empty( $this->gmail['access_token'] ) ) {
$client->setAccessToken( $this->gmail['access_token'] );
}
// Refresh the token if it's expired.
if ( $client->isAccessTokenExpired() ) {
$refresh = $client->getRefreshToken();
if ( empty( $refresh ) && isset( $this->gmail['refresh_token'] ) ) {
$refresh = $this->gmail['refresh_token'];
}
if ( ! empty( $refresh ) ) {
try {
$creds = $client->fetchAccessTokenWithRefreshToken( $refresh );
} catch ( \Exception $e ) {
$creds['error'] = $e->getMessage();
Debug::set( $e->getMessage() );
}
// Bail if we have an error.
if ( ! empty( $creds['error'] ) ) {
return $client;
}
$this->update_access_token( $client->getAccessToken() );
$this->update_refresh_token( $client->getRefreshToken() );
}
}
return $client;
}
/**
* Get the auth code from the $_GET and save it.
* Redirect user back to settings with an error message, if failed.
*
* @since 1.0.0
*/
public function process() {
// We can't process without saved client_id/secret.
if ( ! $this->is_clients_saved() ) {
Debug::set( 'There was an error while processing the Google authentication request. Please make sure that you have Client ID and Client Secret both valid and saved.' );
wp_redirect(
add_query_arg(
'error',
'google_no_clients',
wp_mail_smtp()->get_admin()->get_admin_page_url()
)
);
exit;
}
$code = '';
$scope = '';
$error = '';
if ( isset( $_GET['error'] ) ) {
$error = sanitize_key( $_GET['error'] );
}
// In case of any error: display a message to a user.
if ( ! empty( $error ) ) {
wp_redirect(
add_query_arg(
'error',
'google_' . $error,
wp_mail_smtp()->get_admin()->get_admin_page_url()
)
);
exit;
}
if ( isset( $_GET['code'] ) ) {
$code = $_GET['code'];
}
if ( isset( $_GET['scope'] ) ) {
$scope = urldecode( $_GET['scope'] );
}
// Let's try to get the access token.
if (
! empty( $code ) &&
(
$scope === ( \Google_Service_Gmail::GMAIL_SEND . ' ' . \Google_Service_Gmail::MAIL_GOOGLE_COM ) ||
$scope === \Google_Service_Gmail::GMAIL_SEND
)
) {
// Save the auth code. So \Google_Client can reuse it to retrieve the access token.
$this->update_auth_code( $code );
} else {
wp_redirect(
add_query_arg(
'error',
'google_no_code_scope',
wp_mail_smtp()->get_admin()->get_admin_page_url()
)
);
exit;
}
wp_redirect(
add_query_arg(
'success',
'google_site_linked',
wp_mail_smtp()->get_admin()->get_admin_page_url()
)
);
exit;
}
/**
* Update access token in our DB.
*
* @since 1.0.0
*
* @param array $token
*/
protected function update_access_token( $token ) {
$options = new PluginOptions();
$all = $options->get_all();
$all[ $this->mailer ]['access_token'] = $token;
$this->gmail['access_token'] = $token;
$options->set( $all );
}
/**
* Update refresh token in our DB.
*
* @since 1.0.0
*
* @param array $token
*/
protected function update_refresh_token( $token ) {
$options = new PluginOptions();
$all = $options->get_all();
$all[ $this->mailer ]['refresh_token'] = $token;
$this->gmail['refresh_token'] = $token;
$options->set( $all );
}
/**
* Update auth code in our DB.
*
* @since 1.0.0
*
* @param string $code
*/
protected function update_auth_code( $code ) {
$options = new PluginOptions();
$all = $options->get_all();
$all[ $this->mailer ]['auth_code'] = $code;
$this->gmail['auth_code'] = $code;
$options->set( $all );
}
/**
* Get the auth URL used to proceed to Google to request access to send emails.
*
* @since 1.0.0
*
* @return string
*/
public function get_google_auth_url() {
if (
! empty( $this->client ) &&
class_exists( 'Google_Client', false ) &&
$this->client instanceof \Google_Client
) {
return filter_var( $this->client->createAuthUrl(), FILTER_SANITIZE_URL );
}
return '';
}
/**
* Whether user saved Client ID and Client Secret or not.
* Both options are required.
*
* @since 1.0.0
*
* @return bool
*/
public function is_clients_saved() {
return ! empty( $this->gmail['client_id'] ) && ! empty( $this->gmail['client_secret'] );
}
/**
* Whether we have an access and refresh tokens or not.
*
* @since 1.0.0
*
* @return bool
*/
public function is_auth_required() {
return empty( $this->gmail['access_token'] ) || empty( $this->gmail['refresh_token'] );
}
}
<?php
namespace WPMailSMTP\Providers\Gmail;
use WPMailSMTP\Debug;
use WPMailSMTP\MailCatcher;
use WPMailSMTP\Providers\MailerAbstract;
/**
* Class Mailer.
*
* @since 1.0.0
*/
class Mailer extends MailerAbstract {
/**
* URL to make an API request to.
* Not used for Gmail, as we are using its API.
*
* @var string
*/
protected $url = 'https://www.googleapis.com/upload/gmail/v1/users/userId/messages/send';
/**
* Gmail custom Auth library.
*
* @var Auth
*/
protected $auth;
/**
* Gmail message.
*
* @var \Google_Service_Gmail_Message
*/
protected $message;
/**
* Mailer constructor.
*
* @since 1.0.0
*
* @param \WPMailSMTP\MailCatcher $phpmailer
*/
public function __construct( $phpmailer ) {
parent::__construct( $phpmailer );
if ( ! $this->is_php_compatible() ) {
return;
}
// Include the Google library.
require wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
$this->auth = new Auth();
$this->message = new \Google_Service_Gmail_Message();
}
/**
* Re-use the MailCatcher class methods and properties.
*
* @since 1.2.0
*
* @param \WPMailSMTP\MailCatcher $phpmailer
*/
public function process_phpmailer( $phpmailer ) {
// Make sure that we have access to MailCatcher class methods.
if (
! $phpmailer instanceof MailCatcher &&
! $phpmailer instanceof \PHPMailer
) {
return;
}
$this->phpmailer = $phpmailer;
}
/**
* Use Google API Services to send emails.
*
* @since 1.0.0
*/
public function send() {
// Get the raw MIME email using \MailCatcher data.
$base64 = base64_encode( $this->phpmailer->getSentMIMEMessage() );
$base64 = str_replace( array( '+', '/', '=' ), array( '-', '_', '' ), $base64 ); // url safe.
$this->message->setRaw( $base64 );
$service = new \Google_Service_Gmail( $this->auth->get_client() );
try {
$response = $service->users_messages->send( 'me', $this->message );
$this->process_response( $response );
} catch ( \Exception $e ) {
Debug::set( 'Error while sending via Gmail mailer: ' . $e->getMessage() );
return;
}
}
/**
* Save response from the API to use it later.
*
* @since 1.0.0
*
* @param \Google_Service_Gmail_Message $response
*/
protected function process_response( $response ) {
$this->response = $response;
}
/**
* Check whether the email was sent.
*
* @since 1.0.0
*
* @return bool
*/
public function is_email_sent() {
$is_sent = false;
if ( method_exists( $this->response, 'getId' ) ) {
$message_id = $this->response->getId();
if ( ! empty( $message_id ) ) {
return true;
}
}
return $is_sent;
}
/**
* @inheritdoc
*/
public function get_debug_info() {
$gmail_text = array();
$options = new \WPMailSMTP\Options();
$gmail = $options->get_group( 'gmail' );
$gmail_text[] = '<strong>Client ID/Secret:</strong> ' . ( ! empty( $gmail['client_id'] ) && ! empty( $gmail['client_secret'] ) ? 'Yes' : 'No' );
$gmail_text[] = '<strong>Auth Code:</strong> ' . ( ! empty( $gmail['auth_code'] ) ? 'Yes' : 'No' );
$gmail_text[] = '<strong>Access Token:</strong> ' . ( ! empty( $gmail['access_token'] ) ? 'Yes' : 'No' );
$gmail_text[] = '<br><strong>Server:</strong>';
$gmail_text[] = '<strong>OpenSSL:</strong> ' . ( extension_loaded( 'openssl' ) ? 'Yes' : 'No' );
$gmail_text[] = '<strong>PHP.allow_url_fopen:</strong> ' . ( ini_get( 'allow_url_fopen' ) ? 'Yes' : 'No' );
$gmail_text[] = '<strong>PHP.stream_socket_client():</strong> ' . ( function_exists( 'stream_socket_client' ) ? 'Yes' : 'No' );
$gmail_text[] = '<strong>PHP.fsockopen():</strong> ' . ( function_exists( 'fsockopen' ) ? 'Yes' : 'No' );
$gmail_text[] = '<strong>PHP.curl_version():</strong> ' . ( function_exists( 'curl_version' ) ? 'Yes' : 'No' );
if ( function_exists( 'apache_get_modules' ) ) {
$modules = apache_get_modules();
$gmail_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
}
if ( function_exists( 'selinux_is_enabled' ) ) {
$gmail_text[] = '<strong>OS.SELinux:</strong> ' . ( selinux_is_enabled() ? 'Yes' : 'No' );
}
if ( function_exists( 'grsecurity_is_enabled' ) ) {
$gmail_text[] = '<strong>OS.grsecurity:</strong> ' . ( grsecurity_is_enabled() ? 'Yes' : 'No' );
}
return implode( '<br>', $gmail_text );
}
}
<?php
namespace WPMailSMTP\Providers\Gmail;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Option.
*
* @since 1.0.0
*/
class Options extends OptionsAbstract {
/**
* Mailgun constructor.
*
* @since 1.0.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/gmail.png',
'slug' => 'gmail',
'title' => esc_html__( 'Gmail', 'wp-mail-smtp' ),
'description' => sprintf(
wp_kses(
/* translators: %1$s - opening link tag; %2$s - closing link tag. */
__( 'Send emails using your Gmail or G Suite (formerly Google Apps) account, all while keeping your login credentials safe. Other Google SMTP methods require enabling less secure apps in your account and entering your password. However, this integration uses the Google API to improve email delivery issues while keeping your site secure.<br><br>Read our %1$sGmail documentation%2$s to learn how to configure Gmail or G Suite.', 'wp-mail-smtp' ),
array(
'br' => array(),
'a' => array(
'href' => array(),
'rel' => array(),
'target' => array(),
),
)
),
'<a href="https://wpforms.com/how-to-securely-send-wordpress-emails-using-gmail-smtp/" target="_blank" rel="noopener noreferrer">',
'</a>'
),
'php' => '5.5',
)
);
}
/**
* @inheritdoc
*/
public function display_options() {
// Do not display options if PHP version is not correct.
if ( ! $this->is_php_correct() ) {
$this->display_php_warning();
return;
}
?>
<!-- Client ID -->
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_id" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_id"><?php esc_html_e( 'Client ID', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][client_id]" type="text"
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'client_id' ) ); ?>"
<?php echo $this->options->is_const_defined( $this->get_slug(), 'client_id' ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_id" spellcheck="false"
/>
</div>
</div>
<!-- Client Secret -->
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret"><?php esc_html_e( 'Client Secret', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][client_secret]" type="text"
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'client_secret' ) ); ?>"
<?php echo $this->options->is_const_defined( $this->get_slug(), 'client_secret' ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret" spellcheck="false"
/>
</div>
</div>
<!-- Authorized redirect URI -->
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"><?php esc_html_e( 'Authorized redirect URI', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input type="text" readonly="readonly"
value="<?php echo esc_attr( Auth::get_plugin_auth_url() ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"
/>
<button type="button" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-light-grey wp-mail-smtp-setting-copy"
title="<?php esc_attr_e( 'Copy URL to clipboard', 'wp-mail-smtp' ); ?>"
data-source_id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect">
<span class="dashicons dashicons-admin-page"></span>
</button>
<p class="desc">
<?php esc_html_e( 'This is the path on your site that you will be redirected to after you have authenticated with Google.', 'wp-mail-smtp' ); ?>
<br>
<?php esc_html_e( 'You need to copy this URL into "Authorized redirect URIs" field for you web application on Google APIs site for your project there.', 'wp-mail-smtp' ); ?>
</p>
</div>
</div>
<!-- Auth users button -->
<?php $auth = new Auth(); ?>
<?php if ( $auth->is_clients_saved() && $auth->is_auth_required() ) : ?>
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-authorize" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label><?php esc_html_e( 'Authorize', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<a href="<?php echo esc_url( $auth->get_google_auth_url() ); ?>" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-orange">
<?php esc_html_e( 'Allow plugin to send emails using your Google account', 'wp-mail-smtp' ); ?>
</a>
<p class="desc">
<?php esc_html_e( 'Click the button above to confirm authorization.', 'wp-mail-smtp' ); ?>
</p>
</div>
</div>
<?php endif; ?>
<?php
}
}
<?php
namespace WPMailSMTP\Providers;
use WPMailSMTP\Debug;
use WPMailSMTP\MailCatcher;
use WPMailSMTP\Options;
/**
* Class Loader.
*
* @since 1.0.0
*/
class Loader {
/**
* Key is the mailer option, value is the path to its classes.
*
* @var array
*/
protected $providers = array(
'mail' => 'WPMailSMTP\Providers\Mail\\',
'gmail' => 'WPMailSMTP\Providers\Gmail\\',
'mailgun' => 'WPMailSMTP\Providers\Mailgun\\',
'sendgrid' => 'WPMailSMTP\Providers\Sendgrid\\',
'pepipost' => 'WPMailSMTP\Providers\Pepipost\\',
'smtp' => 'WPMailSMTP\Providers\SMTP\\',
);
/**
* @var \WPMailSMTP\MailCatcher
*/
private $phpmailer;
/**
* Get all the supported providers.
*
* @since 1.0.0
*
* @return array
*/
public function get_providers() {
if ( ! Options::init()->is_pepipost_active() ) {
unset( $this->providers['pepipost'] );
}
return apply_filters( 'wp_mail_smtp_providers_loader_get_providers', $this->providers );
}
/**
* Get a single provider FQN-path based on its name.
*
* @since 1.0.0
*
* @param string $provider
*
* @return array
*/
public function get_provider_path( $provider ) {
$provider = sanitize_key( $provider );
return apply_filters(
'wp_mail_smtp_providers_loader_get_provider_path',
isset( $this->providers[ $provider ] ) ? $this->providers[ $provider ] : null,
$provider
);
}
/**
* Get the provider options, if exists.
*
* @since 1.0.0
*
* @param string $provider
*
* @return \WPMailSMTP\Providers\OptionsAbstract|null
*/
public function get_options( $provider ) {
return $this->get_entity( $provider, 'Options' );
}
/**
* Get all options of all providers.
*
* @since 1.0.0
*
* @return \WPMailSMTP\Providers\OptionsAbstract[]
*/
public function get_options_all() {
$options = array();
foreach ( $this->get_providers() as $provider => $path ) {
$option = $this->get_options( $provider );
if ( ! $option instanceof OptionsAbstract ) {
continue;
}
$slug = $option->get_slug();
$title = $option->get_title();
if ( empty( $title ) || empty( $slug ) ) {
continue;
}
$options[] = $option;
}
return apply_filters( 'wp_mail_smtp_providers_loader_get_providers_all', $options );
}
/**
* Get the provider mailer, if exists.
*
* @since 1.0.0
*
* @param string $provider
* @param MailCatcher $phpmailer
*
* @return \WPMailSMTP\Providers\MailerAbstract|null
*/
public function get_mailer( $provider, $phpmailer ) {
if (
$phpmailer instanceof MailCatcher ||
$phpmailer instanceof \PHPMailer
) {
$this->phpmailer = $phpmailer;
}
return $this->get_entity( $provider, 'Mailer' );
}
/**
* Get the provider auth, if exists.
*
* @param string $provider
*
* @return \WPMailSMTP\Providers\AuthAbstract|null
*/
public function get_auth( $provider ) {
return $this->get_entity( $provider, 'Auth' );
}
/**
* Get a generic entity based on the request.
*
* @uses ReflectionClass
*
* @since 1.0.0
*
* @param string $provider
* @param string $request
*
* @return null
*/
protected function get_entity( $provider, $request ) {
$provider = sanitize_key( $provider );
$request = sanitize_text_field( $request );
$path = $this->get_provider_path( $provider );
$entity = null;
if ( empty( $path ) ) {
return $entity;
}
try {
$reflection = new \ReflectionClass( $path . $request );
if ( file_exists( $reflection->getFileName() ) ) {
$class = $path . $request;
if ( $this->phpmailer ) {
$entity = new $class( $this->phpmailer );
} else {
$entity = new $class();
}
}
} catch ( \Exception $e ) {
Debug::set( "There was a problem while retrieving {$request} for {$provider}: {$e->getMessage()}" );
$entity = null;
}
return apply_filters( 'wp_mail_smtp_providers_loader_get_entity', $entity, $provider, $request );
}
}
<?php
namespace WPMailSMTP\Providers\Mail;
use WPMailSMTP\Providers\MailerAbstract;
/**
* Class Mailer inherits everything from parent abstract class.
* This file is required for a proper work of Loader and \ReflectionClass.
*
* @package WPMailSMTP\Providers\Mail
*/
class Mailer extends MailerAbstract {
/**
* @inheritdoc
*/
public function get_debug_info() {
$mail_text = array();
$mail_text[] = '<br><strong>Server:</strong>';
$disabled_functions = ini_get( 'disable_functions' );
$disabled = (array) explode( ',', trim( $disabled_functions ) );
$mail_text[] = '<strong>PHP.mail():</strong> ' . ( in_array( 'mail', $disabled, true ) || ! function_exists( 'mail' ) ? 'No' : 'Yes' );
if ( function_exists( 'apache_get_modules' ) ) {
$modules = apache_get_modules();
$mail_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
}
if ( function_exists( 'selinux_is_enabled' ) ) {
$mail_text[] = '<strong>OS.SELinux:</strong> ' . ( selinux_is_enabled() ? 'Yes' : 'No' );
}
if ( function_exists( 'grsecurity_is_enabled' ) ) {
$mail_text[] = '<strong>OS.grsecurity:</strong> ' . ( grsecurity_is_enabled() ? 'Yes' : 'No' );
}
return implode( '<br>', $mail_text );
}
}
<?php
namespace WPMailSMTP\Providers\Mail;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Option.
*
* @since 1.0.0
*/
class Options extends OptionsAbstract {
/**
* Mail constructor.
*
* @since 1.0.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/php.png',
'slug' => 'mail',
'title' => esc_html__( 'Default (none)', 'wp-mail-smtp' ),
)
);
}
/**
* @inheritdoc
*/
public function display_options() {
?>
<blockquote>
<?php esc_html_e( 'You currently have the native WordPress option selected. Please select any other Mailer option above to continue the setup.', 'wp-mail-smtp' ); ?>
</blockquote>
<?php
}
}
<?php
namespace WPMailSMTP\Providers;
use WPMailSMTP\Debug;
use WPMailSMTP\MailCatcher;
use WPMailSMTP\Options;
/**
* Class MailerAbstract.
*
* @since 1.0.0
*/
abstract class MailerAbstract implements MailerInterface {
/**
* Which response code from HTTP provider is considered to be successful?
*
* @var int
*/
protected $email_sent_code = 200;
/**
* @var Options
*/
protected $options;
/**
* @var MailCatcher
*/
protected $phpmailer;
/**
* @var string
*/
protected $mailer = '';
/**
* URL to make an API request to.
*
* @var string
*/
protected $url = '';
/**
* @var array
*/
protected $headers = array();
/**
* @var array
*/
protected $body = array();
/**
* @var mixed
*/
protected $response = array();
/**
* Mailer constructor.
*
* @since 1.0.0
*
* @param MailCatcher $phpmailer
*/
public function __construct( MailCatcher $phpmailer ) {
$this->options = new Options();
$this->mailer = $this->options->get( 'mail', 'mailer' );
// Only non-SMTP mailers need URL.
if ( ! $this->options->is_mailer_smtp() && empty( $this->url ) ) {
return;
}
$this->process_phpmailer( $phpmailer );
}
/**
* Re-use the MailCatcher class methods and properties.
*
* @since 1.0.0
*
* @param MailCatcher $phpmailer
*/
public function process_phpmailer( $phpmailer ) {
// Make sure that we have access to MailCatcher class methods.
if (
! $phpmailer instanceof MailCatcher &&
! $phpmailer instanceof \PHPMailer
) {
return;
}
$this->phpmailer = $phpmailer;
// Prevent working with those methods, as they are not needed for SMTP-like mailers.
if ( $this->options->is_mailer_smtp() ) {
return;
}
$this->set_headers( $this->phpmailer->getCustomHeaders() );
$this->set_from( $this->phpmailer->From, $this->phpmailer->FromName );
$this->set_recipients(
array(
'to' => $this->phpmailer->getToAddresses(),
'cc' => $this->phpmailer->getCcAddresses(),
'bcc' => $this->phpmailer->getBccAddresses(),
)
);
$this->set_subject( $this->phpmailer->Subject );
$this->set_content(
array(
'html' => $this->phpmailer->Body,
'text' => $this->phpmailer->AltBody,
)
);
$this->set_return_path( $this->phpmailer->From );
$this->set_reply_to( $this->phpmailer->getReplyToAddresses() );
/*
* In some cases we will need to modify the internal structure
* of the body content, if attachments are present.
* So lets make this call the last one.
*/
$this->set_attachments( $this->phpmailer->getAttachments() );
}
/**
* @inheritdoc
*/
public function set_subject( $subject ) {
$this->set_body_param(
array(
'subject' => $subject,
)
);
}
/**
* Set the request params, that goes to the body of the HTTP request.
*
* @since 1.0.0
*
* @param array $param Key=>value of what should be sent to a 3rd party API.
*
* @internal param array $params
*/
protected function set_body_param( $param ) {
$this->body = Options::array_merge_recursive( $this->body, $param );
}
/**
* @inheritdoc
*/
public function set_headers( $headers ) {
foreach ( $headers as $header ) {
$name = isset( $header[0] ) ? $header[0] : false;
$value = isset( $header[1] ) ? $header[1] : false;
if ( empty( $name ) || empty( $value ) ) {
continue;
}
$this->set_header( $name, $value );
}
}
/**
* @inheritdoc
*/
public function set_header( $name, $value ) {
$process_value = function ( $value ) {
// Remove HTML tags.
$filtered = wp_strip_all_tags( $value, false );
// Remove multi-lines/tabs.
$filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
// Remove whitespaces.
$filtered = trim( $filtered );
// Remove octets.
$found = false;
while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
$filtered = str_replace( $match[0], '', $filtered );
$found = true;
}
if ( $found ) {
// Strip out the whitespace that may now exist after removing the octets.
$filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
}
return $filtered;
};
$name = sanitize_text_field( $name );
if ( empty( $name ) ) {
return;
}
$value = $process_value( $value );
$this->headers[ $name ] = $value;
}
/**
* @inheritdoc
*/
public function get_body() {
return apply_filters( 'wp_mail_smtp_providers_mailer_get_body', $this->body );
}
/**
* @inheritdoc
*/
public function get_headers() {
return apply_filters( 'wp_mail_smtp_providers_mailer_get_headers', $this->headers );
}
/**
* @inheritdoc
*/
public function send() {
$params = Options::array_merge_recursive( $this->get_default_params(), array(
'headers' => $this->get_headers(),
'body' => $this->get_body(),
) );
$response = wp_safe_remote_post( $this->url, $params );
$this->process_response( $response );
}
/**
* We might need to do something after the email was sent to the API.
* In this method we preprocess the response from the API.
*
* @since 1.0.0
*
* @param array|\WP_Error $response
*/
protected function process_response( $response ) {
if ( is_wp_error( $response ) ) {
// Save the error text.
$errors = $response->get_error_messages();
foreach ( $errors as $error ) {
Debug::set( $error );
}
return;
}
if ( isset( $response['body'] ) && $this->is_json( $response['body'] ) ) {
$response['body'] = \json_decode( $response['body'] );
}
$this->response = $response;
}
/**
* Get the default params, required for wp_safe_remote_post().
*
* @since 1.0.0
*
* @return array
*/
protected function get_default_params() {
return apply_filters( 'wp_mail_smtp_providers_mailer_get_default_params', array(
'timeout' => 15,
'httpversion' => '1.1',
'blocking' => true,
) );
}
/**
* @inheritdoc
*/
public function is_email_sent() {
$is_sent = false;
if ( wp_remote_retrieve_response_code( $this->response ) === $this->email_sent_code ) {
$is_sent = true;
} else {
$error = $this->get_response_error();
if ( ! empty( $error ) ) {
Debug::set( $error );
}
}
return apply_filters( 'wp_mail_smtp_providers_mailer_is_email_sent', $is_sent );
}
/**
* Should be overwritten when appropriate.
*
* @since 1.2.0
*
* @return string
*/
protected function get_response_error() {
return '';
}
/**
* @inheritdoc
*/
public function is_php_compatible() {
$options = wp_mail_smtp()->get_providers()->get_options( $this->mailer );
return version_compare( phpversion(), $options->get_php_version(), '>=' );
}
/**
* Check whether the string is a JSON or not.
*
* @since 1.0.0
*
* @param string $string
*
* @return bool
*/
protected function is_json( $string ) {
return is_string( $string ) && is_array( json_decode( $string, true ) ) && ( json_last_error() === JSON_ERROR_NONE ) ? true : false;
}
/**
* This method is relevant to SMTP and Pepipost.
* All other custom mailers should override it with own information.
*
* @since 1.2.0
*
* @return string
*/
public function get_debug_info() {
global $phpmailer;
$smtp_text = array();
// Mail mailer has nothing to return.
if ( $this->options->is_mailer_smtp() ) {
$smtp_text[] = '<strong>ErrorInfo:</strong> ' . make_clickable( wp_strip_all_tags( $phpmailer->ErrorInfo ) );
$smtp_text[] = '<strong>Host:</strong> ' . $phpmailer->Host;
$smtp_text[] = '<strong>Port:</strong> ' . $phpmailer->Port;
$smtp_text[] = '<strong>SMTPSecure:</strong> ' . Debug::pvar( $phpmailer->SMTPSecure );
$smtp_text[] = '<strong>SMTPAutoTLS:</strong> ' . Debug::pvar( $phpmailer->SMTPAutoTLS );
$smtp_text[] = '<strong>SMTPAuth:</strong> ' . Debug::pvar( $phpmailer->SMTPAuth );
if ( ! empty( $phpmailer->SMTPOptions ) ) {
$smtp_text[] = '<strong>SMTPOptions:</strong> <code>' . json_encode( $phpmailer->SMTPOptions ) . '</code>';
}
}
$smtp_text[] = '<br><strong>Server:</strong>';
$smtp_text[] = '<strong>OpenSSL:</strong> ' . ( extension_loaded( 'openssl' ) ? 'Yes' : 'No' );
if ( function_exists( 'apache_get_modules' ) ) {
$modules = apache_get_modules();
$smtp_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
}
if ( function_exists( 'selinux_is_enabled' ) ) {
$smtp_text[] = '<strong>OS.SELinux:</strong> ' . ( selinux_is_enabled() ? 'Yes' : 'No' );
}
if ( function_exists( 'grsecurity_is_enabled' ) ) {
$smtp_text[] = '<strong>OS.grsecurity:</strong> ' . ( grsecurity_is_enabled() ? 'Yes' : 'No' );
}
return implode( '<br>', $smtp_text );
}
}
<?php
namespace WPMailSMTP\Providers;
/**
* Interface MailerInterface.
*
* @since 1.0.0
*/
interface MailerInterface {
/**
* Send the email.
*
* @since 1.0.0
*/
public function send();
/**
* Whether the email is sent or not.
* We basically check the response code from a request to provider.
* Might not be 100% correct, not guarantees that email is delivered.
*
* @since 1.0.0
*
* @return bool
*/
public function is_email_sent();
/**
* Whether the mailer supports the current PHP version or not.
*
* @since 1.0.0
*
* @return bool
*/
public function is_php_compatible();
/**
* Get the email body.
*
* @since 1.0.0
*
* @return string|array
*/
public function get_body();
/**
* Get the email headers.
*
* @since 1.0.0
*
* @return array
*/
public function get_headers();
/**
* Get an array of all debug information relevant to the mailer.
*
* @since 1.2.0
*
* @return array
*/
public function get_debug_info();
/**
* Re-use the MailCatcher class methods and properties.
*
* @since 1.2.0
*
* @param \WPMailSMTP\MailCatcher $phpmailer
*/
public function process_phpmailer( $phpmailer );
}
<?php
namespace WPMailSMTP\Providers\Mailgun;
use WPMailSMTP\Providers\MailerAbstract;
/**
* Class Mailer.
*
* @since 1.0.0
*/
class Mailer extends MailerAbstract {
/**
* Which response code from HTTP provider is considered to be successful?
*
* @var int
*/
protected $email_sent_code = 200;
/**
* URL to make an API request to.
*
* @var string
*/
protected $url = 'https://api.mailgun.net/v3/';
/**
* @inheritdoc
*/
public function __construct( $phpmailer ) {
// We want to prefill everything from \WPMailSMTP\MailCatcher class, which extends \PHPMailer.
parent::__construct( $phpmailer );
/*
* Append the url with a domain,
* to avoid passing the domain name as a query parameter with all requests.
*/
$this->url .= sanitize_text_field( $this->options->get( $this->mailer, 'domain' ) . '/messages' );
$this->set_header( 'Authorization', 'Basic ' . base64_encode( 'api:' . $this->options->get( $this->mailer, 'api_key' ) ) );
}
/**
* @inheritdoc
*/
public function set_from( $email, $name = '' ) {
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
return;
}
if ( ! empty( $name ) ) {
$this->set_body_param(
array(
'from' => $name . ' <' . $email . '>',
)
);
} else {
$this->set_body_param(
array(
'from' => $email,
)
);
}
}
/**
* @inheritdoc
*/
public function set_recipients( $recipients ) {
if ( empty( $recipients ) ) {
return;
}
$default = array( 'to', 'cc', 'bcc' );
foreach ( $recipients as $kind => $emails ) {
if (
! in_array( $kind, $default, true ) ||
empty( $emails ) ||
! is_array( $emails )
) {
continue;
}
$data = array();
foreach ( $emails as $email ) {
$addr = isset( $email[0] ) ? $email[0] : false;
$name = isset( $email[1] ) ? $email[1] : false;
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
continue;
}
if ( ! empty( $name ) ) {
$data[] = $name . ' <' . $addr . '>';
} else {
$data[] = $addr;
}
}
if ( ! empty( $data ) ) {
$this->set_body_param(
array(
$kind => implode( ', ', $data ),
)
);
}
}
}
/**
* @inheritdoc
*/
public function set_content( $content ) {
if ( is_array( $content ) ) {
$default = array( 'text', 'html' );
foreach ( $content as $type => $mail ) {
if (
! in_array( $type, $default, true ) ||
empty( $mail )
) {
continue;
}
$this->set_body_param(
array(
$type => $mail,
)
);
}
} else {
$type = 'text';
if ( $this->phpmailer->ContentType === 'text/html' ) {
$type = 'html';
}
if ( ! empty( $content ) ) {
$this->set_body_param(
array(
$type => $content,
)
);
}
}
}
/**
* It's the last one, so we can modify the whole body.
*
* @since 1.0.0
*
* @param array $attachments
*/
public function set_attachments( $attachments ) {
if ( empty( $attachments ) ) {
return;
}
$payload = '';
$data = array();
foreach ( $attachments as $attachment ) {
$file = false;
/*
* We are not using WP_Filesystem API as we can't reliably work with it.
* It is not always available, same as credentials for FTP.
*/
try {
if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
$file = file_get_contents( $attachment[0] );
}
} catch ( \Exception $e ) {
$file = false;
}
if ( $file === false ) {
continue;
}
$data[] = array(
'content' => $file,
'name' => $attachment[1],
);
}
if ( ! empty( $data ) ) {
// First, generate a boundary for the multipart message.
$boundary = base_convert( uniqid( 'boundary', true ), 10, 36 );
// Iterate through pre-built params and build a payload.
foreach ( $this->body as $key => $value ) {
if ( is_array( $value ) ) {
foreach ( $value as $child_key => $child_value ) {
$payload .= '--' . $boundary;
$payload .= "\r\n";
$payload .= 'Content-Disposition: form-data; name="' . $key . "\"\r\n\r\n";
$payload .= $child_value;
$payload .= "\r\n";
}
} else {
$payload .= '--' . $boundary;
$payload .= "\r\n";
$payload .= 'Content-Disposition: form-data; name="' . $key . '"' . "\r\n\r\n";
$payload .= $value;
$payload .= "\r\n";
}
}
// Now iterate through our attachments, and add them too.
foreach ( $data as $key => $attachment ) {
$payload .= '--' . $boundary;
$payload .= "\r\n";
$payload .= 'Content-Disposition: form-data; name="attachment[' . $key . ']"; filename="' . $attachment['name'] . '"' . "\r\n\r\n";
$payload .= $attachment['content'];
$payload .= "\r\n";
}
$payload .= '--' . $boundary . '--';
// Redefine the body the "dirty way".
$this->body = $payload;
$this->set_header( 'Content-Type', 'multipart/form-data; boundary=' . $boundary );
}
}
/**
* @inheritdoc
*/
public function set_reply_to( $reply_to ) {
if ( empty( $reply_to ) ) {
return;
}
$data = array();
foreach ( $reply_to as $key => $emails ) {
if (
empty( $emails ) ||
! is_array( $emails )
) {
continue;
}
$addr = isset( $emails[0] ) ? $emails[0] : false;
$name = isset( $emails[1] ) ? $emails[1] : false;
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
continue;
}
if ( ! empty( $name ) ) {
$data[] = $name . ' <' . $addr . '>';
} else {
$data[] = $addr;
}
}
if ( ! empty( $data ) ) {
$this->set_body_param(
array(
'h:Reply-To' => implode( ',', $data ),
)
);
}
}
/**
* @inheritdoc
*/
public function set_return_path( $email ) {
if (
$this->options->get( 'mail', 'return_path' ) !== true ||
! filter_var( $email, FILTER_VALIDATE_EMAIL )
) {
return;
}
$this->set_body_param(
array(
'sender' => $email,
)
);
}
/**
* Get a Mailgun-specific response with a helpful error.
*
* @since 1.2.0
*
* @return string
*/
protected function get_response_error() {
$body = (array) wp_remote_retrieve_body( $this->response );
$error_text = array();
if ( ! empty( $body['message'] ) ) {
if ( is_string( $body['message'] ) ) {
$error_text[] = $body['message'];
} else {
$error_text[] = \json_encode( $body['message'] );
}
} elseif ( ! empty( $body[0] ) ) {
if ( is_string( $body[0] ) ) {
$error_text[] = $body[0];
} else {
$error_text[] = \json_encode( $body[0] );
}
}
return implode( '<br>', array_map( 'esc_textarea', $error_text ) );
}
/**
* @inheritdoc
*/
public function get_debug_info() {
$mg_text = array();
$options = new \WPMailSMTP\Options();
$mailgun = $options->get_group( 'mailgun' );
$mg_text[] = '<strong>Api Key / Domain:</strong> ' . ( ! empty( $mailgun['api_key'] ) && ! empty( $mailgun['domain'] ) ? 'Yes' : 'No' );
return implode( '<br>', $mg_text );
}
}
<?php
namespace WPMailSMTP\Providers\Mailgun;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Option.
*
* @since 1.0.0
*/
class Options extends OptionsAbstract {
/**
* Mailgun constructor.
*
* @since 1.0.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/mailgun.png',
'slug' => 'mailgun',
'title' => esc_html__( 'Mailgun', 'wp-mail-smtp' ),
'description' => sprintf(
wp_kses(
/* translators: %1$s - opening link tag; %2$s - closing link tag; %3$s - opening link tag; %4$s - closing link tag. */
__( '%1$sMailgun%2$s is one of the leading transactional email services trusted by over 10,000 website and application developers. They provide users 10,000 free emails per month.<br><br>Read our %3$sMailgun documentation%4$s to learn how to configure Mailgun and improve your email deliverability.', 'wp-mail-smtp' ),
array(
'br' => array(),
'a' => array(
'href' => array(),
'rel' => array(),
'target' => array(),
),
)
),
'<a href="https://www.mailgun.com" target="_blank" rel="noopener noreferrer">',
'</a>',
'<a href="https://wpforms.com/how-to-send-wordpress-emails-with-mailgun/" target="_blank" rel="noopener noreferrer">',
'</a>'
),
)
);
}
/**
* @inheritdoc
*/
public function display_options() {
?>
<!-- API Key -->
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'Private API Key', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]" type="text"
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
<?php echo $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" spellcheck="false"
/>
<p class="desc">
<?php
printf(
/* translators: %s - API key link. */
esc_html__( 'Follow this link to get an API Key from Mailgun: %s.', 'wp-mail-smtp' ),
'<a href="https://app.mailgun.com/app/account/security" target="_blank" rel="noopener noreferrer">' .
esc_html__( 'Get a Private API Key', 'wp-mail-smtp' ) .
'</a>'
);
?>
</p>
</div>
</div>
<!-- Domain -->
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-domain" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-domain"><?php esc_html_e( 'Domain Name', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][domain]" type="text"
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'domain' ) ); ?>"
<?php echo $this->options->is_const_defined( $this->get_slug(), 'domain' ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-domain" spellcheck="false"
/>
<p class="desc">
<?php
printf(
/* translators: %s - Domain Name link. */
esc_html__( 'Follow this link to get a Domain Name from Mailgun: %s.', 'wp-mail-smtp' ),
'<a href="https://app.mailgun.com/app/domains" target="_blank" rel="noopener noreferrer">' .
esc_html__( 'Get a Domain Name', 'wp-mail-smtp' ) .
'</a>'
);
?>
</p>
</div>
</div>
<?php
}
}
<?php
namespace WPMailSMTP\Providers;
/**
* Interface ProviderInterface, shared between all current and future providers.
* Defines required methods across all providers.
*
* @since 1.0.0
*/
interface OptionsInterface {
/**
* Get the mailer provider slug.
*
* @since 1.0.0
*
* @return string
*/
public function get_slug();
/**
* Get the mailer provider title (or name).
*
* @since 1.0.0
*
* @return string
*/
public function get_title();
/**
* Get the mailer provider description.
*
* @since 1.0.0
*
* @return string
*/
public function get_description();
/**
* Get the mailer provider minimum PHP version.
*
* @since 1.0.0
*
* @return string
*/
public function get_php_version();
/**
* Get the mailer provider logo URL.
*
* @since 1.0.0
*
* @return string
*/
public function get_logo_url();
/**
* Output the mailer provider options.
*
* @since 1.0.0
*/
public function display_options();
}
<?php
namespace WPMailSMTP\Providers\Pepipost;
use WPMailSMTP\Providers\MailerAbstract;
/**
* Class Mailer inherits everything from parent abstract class.
* This file is required for a proper work of Loader and \ReflectionClass.
*
* @package WPMailSMTP\Providers\Pepipost
*/
class Mailer extends MailerAbstract {
}
<?php
namespace WPMailSMTP\Providers\Pepipost;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Options.
*
* @since 1.0.0
*/
class Options extends OptionsAbstract {
/**
* Pepipost constructor.
*
* @since 1.0.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/pepipost.png',
'slug' => 'pepipost',
'title' => esc_html__( 'Pepipost', 'wp-mail-smtp' ),
)
);
}
}
<?php
namespace WPMailSMTP\Providers\SMTP;
use WPMailSMTP\Providers\MailerAbstract;
/**
* Class Mailer inherits everything from parent abstract class.
* This file is required for a proper work of Loader and \ReflectionClass.
*
* @package WPMailSMTP\Providers\SMTP
*/
class Mailer extends MailerAbstract {
}
<?php
namespace WPMailSMTP\Providers\SMTP;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class SMTP.
*
* @since 1.0.0
*/
class Options extends OptionsAbstract {
/**
* SMTP constructor.
*
* @since 1.0.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/smtp.png',
'slug' => 'smtp',
'title' => esc_html__( 'Other SMTP', 'wp-mail-smtp' ),
/* translators: %1$s - opening link tag; %2$s - closing link tag. */
'description' => sprintf(
wp_kses(
__( 'Use the SMTP details provided by your hosting provider or email service.<br><br>To see recommended settings for the popular services as well as troubleshooting tips, check out our %1$sSMTP documentation%2$s.', 'wp-mail-smtp' ),
array(
'br' => array(),
'a' => array(
'href' => array(),
'rel' => array(),
'target' => array(),
),
)
),
'<a href="https://wpforms.com/docs/how-to-set-up-smtp-using-the-wp-mail-smtp-plugin/" target="_blank" rel="noopener noreferrer">',
'</a>'
),
)
);
}
}
<?php
namespace WPMailSMTP\Providers\Sendgrid;
use WPMailSMTP\Providers\MailerAbstract;
/**
* Class Mailer.
*
* @since 1.0.0
*/
class Mailer extends MailerAbstract {
/**
* Which response code from HTTP provider is considered to be successful?
*
* @var int
*/
protected $email_sent_code = 202;
/**
* URL to make an API request to.
*
* @var string
*/
protected $url = 'https://api.sendgrid.com/v3/mail/send';
/**
* Mailer constructor.
*
* @since 1.0.0
*
* @param \WPMailSMTP\MailCatcher $phpmailer
*/
public function __construct( $phpmailer ) {
// We want to prefill everything from \WPMailSMTP\MailCatcher class, which extends \PHPMailer.
parent::__construct( $phpmailer );
$this->set_header( 'Authorization', 'Bearer ' . $this->options->get( $this->mailer, 'api_key' ) );
$this->set_header( 'content-type', 'application/json' );
}
/**
* Redefine the way email body is returned.
* By default we are sending an array of data.
* SendGrid requires a JSON, so we encode the body.
*
* @since 1.0.0
*/
public function get_body() {
$body = parent::get_body();
return wp_json_encode( $body );
}
/**
* @inheritdoc
*/
public function set_from( $email, $name = '' ) {
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
return;
}
$from['email'] = $email;
if ( ! empty( $name ) ) {
$from['name'] = $name;
}
$this->set_body_param(
array(
'from' => $from,
)
);
}
/**
* @inheritdoc
*/
public function set_recipients( $recipients ) {
if ( empty( $recipients ) ) {
return;
}
// Allow for now only these recipient types.
$default = array( 'to', 'cc', 'bcc' );
$data = array();
foreach ( $recipients as $type => $emails ) {
if (
! in_array( $type, $default, true ) ||
empty( $emails ) ||
! is_array( $emails )
) {
continue;
}
$data[ $type ] = array();
// Iterate over all emails for each type.
// There might be multiple cc/to/bcc emails.
foreach ( $emails as $email ) {
$holder = array();
$addr = isset( $email[0] ) ? $email[0] : false;
$name = isset( $email[1] ) ? $email[1] : false;
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
continue;
}
$holder['email'] = $addr;
if ( ! empty( $name ) ) {
$holder['name'] = $name;
}
array_push( $data[ $type ], $holder );
}
}
if ( ! empty( $data ) ) {
$this->set_body_param(
array(
'personalizations' => array( $data ),
)
);
}
}
/**
* @inheritdoc
*/
public function set_content( $content ) {
if ( empty( $content ) ) {
return;
}
if ( is_array( $content ) ) {
$default = array( 'text', 'html' );
$data = array();
foreach ( $content as $type => $body ) {
if (
! in_array( $type, $default, true ) ||
empty( $body )
) {
continue;
}
$content_type = 'text/plain';
$content_value = $body;
if ( $type === 'html' ) {
$content_type = 'text/html';
}
$data[] = array(
'type' => $content_type,
'value' => $content_value,
);
}
$this->set_body_param(
array(
'content' => $data,
)
);
} else {
$data['type'] = 'text/plain';
$data['value'] = $content;
if ( $this->phpmailer->ContentType === 'text/html' ) {
$data['type'] = 'text/html';
}
$this->set_body_param(
array(
'content' => array( $data ),
)
);
}
}
/**
* SendGrid accepts an array of files content in body, so we will include all files and send.
* Doesn't handle exceeding the limits etc, as this is done and reported be SendGrid API.
*
* @since 1.0.0
*
* @param array $attachments
*/
public function set_attachments( $attachments ) {
if ( empty( $attachments ) ) {
return;
}
$data = array();
foreach ( $attachments as $attachment ) {
$file = false;
/*
* We are not using WP_Filesystem API as we can't reliably work with it.
* It is not always available, same as credentials for FTP.
*/
try {
if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
$file = file_get_contents( $attachment[0] );
}
}
catch ( \Exception $e ) {
$file = false;
}
if ( $file === false ) {
continue;
}
$data[] = array(
'content' => base64_encode( $file ),
'type' => $attachment[4],
'filename' => $attachment[1],
'disposition' => $attachment[6],
);
}
if ( ! empty( $data ) ) {
$this->set_body_param(
array(
'attachments' => $data,
)
);
}
}
/**
* @inheritdoc
*/
public function set_reply_to( $reply_to ) {
if ( empty( $reply_to ) ) {
return;
}
$data = array();
foreach ( $reply_to as $key => $emails ) {
if (
empty( $emails ) ||
! is_array( $emails )
) {
continue;
}
$addr = isset( $emails[0] ) ? $emails[0] : false;
$name = isset( $emails[1] ) ? $emails[1] : false;
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
continue;
}
$data['email'] = $addr;
if ( ! empty( $name ) ) {
$data['name'] = $name;
}
break;
}
if ( ! empty( $data ) ) {
$this->set_body_param(
array(
'reply_to' => $data,
)
);
}
}
/**
* SendGrid doesn't support sender or return_path params.
* So we do nothing.
*
* @since 1.0.0
*
* @param string $email
*/
public function set_return_path( $email ) {
}
/**
* Get a SendGrid-specific response with a helpful error.
*
* @since 1.2.0
*
* @return string
*/
protected function get_response_error() {
$body = (array) wp_remote_retrieve_body( $this->response );
$error_text = array();
if ( ! empty( $body['errors'] ) ) {
foreach ( $body['errors'] as $error ) {
if ( property_exists( $error, 'message' ) ) {
// Prepare additional information from SendGrid API.
$extra = '';
if ( property_exists( $error, 'field' ) && ! empty( $error->field ) ) {
$extra .= $error->field . '; ';
}
if ( property_exists( $error, 'help' ) && ! empty( $error->help ) ) {
$extra .= $error->help;
}
// Assign both the main message and perhaps extra information, if exists.
$error_text[] = $error->message . ( ! empty( $extra ) ? ' - ' . $extra : '' );
}
}
}
return implode( '<br>', array_map( 'esc_textarea', $error_text ) );
}
/**
* @inheritdoc
*/
public function get_debug_info() {
$mg_text = array();
$options = new \WPMailSMTP\Options();
$mailgun = $options->get_group( 'sendgrid' );
$mg_text[] = '<strong>Api Key:</strong> ' . ( ! empty( $mailgun['api_key'] ) ? 'Yes' : 'No' );
return implode( '<br>', $mg_text );
}
}
<?php
namespace WPMailSMTP\Providers\Sendgrid;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Option.
*
* @since 1.0.0
*/
class Options extends OptionsAbstract {
/**
* Options constructor.
*
* @since 1.0.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->plugin_url . '/assets/images/sendgrid.png',
'slug' => 'sendgrid',
'title' => esc_html__( 'SendGrid', 'wp-mail-smtp' ),
'description' => sprintf(
wp_kses(
/* translators: %1$s - opening link tag; %2$s - closing link tag; %3$s - opening link tag; %4$s - closing link tag. */
__( '%1$sSendGrid%2$s is one of the leading transactional email services, sending over 35 billion emails every month. They provide users 100 free emails per month.<br><br>Read our %3$sSendGrid documentation%4$s to learn how to set up SendGrid and improve your email deliverability.', 'wp-mail-smtp' ),
array(
'br' => array(),
'a' => array(
'href' => array(),
'rel' => array(),
'target' => array(),
),
)
),
'<a href="https://sendgrid.com" target="_blank" rel="noopener noreferrer">',
'</a>',
'<a href="https://wpforms.com/fix-wordpress-email-notifications-with-sendgrid/" target="_blank" rel="noopener noreferrer">',
'</a>'
),
)
);
}
/**
* @inheritdoc
*/
public function display_options() {
?>
<!-- API Key -->
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'API Key', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]" type="text"
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
<?php echo $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" spellcheck="false"
/>
<p class="desc">
<?php
printf(
/* translators: %s - API key link. */
esc_html__( 'Follow this link to get an API Key from SendGrid: %s.', 'wp-mail-smtp' ),
'<a href="https://app.sendgrid.com/settings/api_keys" target="_blank" rel="noopener noreferrer">' .
esc_html__( 'Create API Key', 'wp-mail-smtp' ) .
'</a>'
);
?>
<br/>
<?php
printf(
/* translators: %s - SendGrid access level. */
esc_html__( 'To send emails you will need only a %s access level for this API key.', 'wp-mail-smtp' ),
'<code>Mail Send</code>'
);
?>
</p>
</div>
</div>
<?php
}
}
<?php
namespace WPMailSMTP;
/**
* Class Upgrade helps upgrade plugin options and similar tasks when the
* occasion arises.
*
* @since 1.1.0
*/
class Upgrade {
/**
* Upgrade constructor.
*
* @since 1.1.0
*/
public function __construct() {
$upgrades = $this->upgrades();
if ( empty( $upgrades ) ) {
return;
}
// Run any available upgrades.
foreach ( $upgrades as $upgrade ) {
$this->{$upgrade}();
}
// Update version post upgrade(s).
update_option( 'wp_mail_smtp_version', WPMS_PLUGIN_VER );
}
/**
* Whether we need to perform an upgrade.
*
* @since 1.1.0
*
* @return array
*/
protected function upgrades() {
$version = get_option( 'wp_mail_smtp_version' );
$upgrades = array();
// Version 1.1.0 upgrade; prior to this the option was not available.
if ( empty( $version ) ) {
$upgrades[] = 'v110_upgrade';
}
return $upgrades;
}
/**
* Upgrade routine for v1.1.0.
*
* Set SMTPAutoTLS to true.
*
* @since 1.1.0
*/
public function v110_upgrade() {
$values = Options::init()->get_all();
// Enable SMTPAutoTLS option.
$values['smtp']['autotls'] = true;
Options::init()->set( $values );
}
}
<?php
namespace WPMailSMTP;
/**
* Class WP provides WordPress shortcuts.
*
* @since 1.0.0
*/
class WP {
/**
* The "queue" of notices.
*
* @var array
*/
protected static $admin_notices = array();
/**
* @var string
*/
const ADMIN_NOTICE_SUCCESS = 'notice-success';
/**
* @var string
*/
const ADMIN_NOTICE_ERROR = 'notice-error';
/**
* @var string
*/
const ADMIN_NOTICE_INFO = 'notice-info';
/**
* @var string
*/
const ADMIN_NOTICE_WARNING = 'notice-warning';
/**
* True is WP is processing an AJAX call.
*
* @since 1.0.0
*
* @return bool
*/
public static function is_doing_ajax() {
if ( function_exists( 'wp_doing_ajax' ) ) {
return wp_doing_ajax();
}
return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
}
/**
* True if I am in the Admin Panel, not doing AJAX.
*
* @since 1.0.0
*
* @return bool
*/
public static function in_wp_admin() {
return ( is_admin() && ! self::is_doing_ajax() );
}
/**
* Add a notice to the "queue of notices".
*
* @since 1.0.0
*
* @param string $message Message text (HTML is OK).
* @param string $class Display class (severity).
*/
public static function add_admin_notice( $message, $class = self::ADMIN_NOTICE_INFO ) {
self::$admin_notices[] = array(
'message' => $message,
'class' => $class,
);
}
/**
* Display all notices.
*
* @since 1.0.0
*/
public static function display_admin_notices() {
foreach ( (array) self::$admin_notices as $notice ) : ?>
<div id="message" class="<?php echo esc_attr( $notice['class'] ); ?> notice is-dismissible">
<p>
<?php echo $notice['message']; ?>
</p>
</div>
<?php
endforeach;
}
/**
* Check whether WP_DEBUG is active.
*
* @since 1.0.0
*
* @return bool
*/
public static function is_debug() {
return defined( 'WP_DEBUG' ) && WP_DEBUG;
}
/**
* Shortcut to global $wpdb.
*
* @since 1.0.0
*
* @return \wpdb
*/
public static function wpdb() {
global $wpdb;
return $wpdb;
}
/**
* Get the postfix for assets files - ".min" or empty.
* ".min" if in production mode.
*
* @since 1.0.0
*
* @return string
*/
public static function asset_min() {
$min = '.min';
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
$min = '';
}
return $min;
}
}
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitbd625bfb904527ebcdc364a59295e538::getLoader();
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
<?php
// autoload_files.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php',
'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
'decc78cc4436b1292c6c0d151b19445c' => $vendorDir . '/phpseclib/phpseclib/phpseclib/bootstrap.php',
'36d9695c51c127dacf01b83c468dbbdb' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail.php',
'd95a5932fb3c05855cde09b51efec1ac' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Message.php',
'1a8cb0c91ca8ad9f9147193a084f80bd' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Resource/Users.php',
'5d5f545fa7a58b1185f901d0c1006a41' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Resource/UsersDrafts.php',
'79c900432abc031cbad7036b9fce5523' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Resource/UsersHistory.php',
'1a56422ddba9140c62183b59448a7227' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Resource/UsersLabels.php',
'f7d0eb6d1da014e7ff1b6038c3314921' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Resource/UsersMessages.php',
'ed22ed3db05c96f75d2885e41650be07' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Resource/UsersMessagesAttachments.php',
'535c184b9a328f2295fc70c028f13aa7' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Resource/UsersSettings.php',
'fc9b994b4190b187884a1bb5b334c54d' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Resource/UsersSettingsFilters.php',
'3a081d084d3ba366d67d7139e5d9fbcf' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Resource/UsersSettingsForwardingAddresses.php',
'60d509e933e5ca336a897bb7b549f15b' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Resource/UsersSettingsSendAs.php',
'39c11aa4169566f44661343f8929bbd0' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Resource/UsersSettingsSendAsSmimeInfo.php',
'cf7f0634ca5d41f748c82f89bd3e960b' => $vendorDir . '/google/apiclient-services/src/Google/Service/Gmail/Resource/UsersThreads.php',
);
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Google_Service_' => array($vendorDir . '/google/apiclient-services/src'),
'Google_' => array($vendorDir . '/google/apiclient/src'),
);
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'phpseclib\\' => array($vendorDir . '/phpseclib/phpseclib/phpseclib'),
'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'),
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'),
'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'),
'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'),
'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
'Google\\Auth\\' => array($vendorDir . '/google/auth/src'),
'Firebase\\JWT\\' => array($vendorDir . '/firebase/php-jwt/src'),
'Composer\\Installers\\' => array($vendorDir . '/composer/installers/src/Composer/Installers'),
);
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitbd625bfb904527ebcdc364a59295e538
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitbd625bfb904527ebcdc364a59295e538', 'loadClassLoader'), true, false);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitbd625bfb904527ebcdc364a59295e538', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitbd625bfb904527ebcdc364a59295e538::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}
$loader->setClassMapAuthoritative(true);
$loader->register(false);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitbd625bfb904527ebcdc364a59295e538::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirebd625bfb904527ebcdc364a59295e538($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequirebd625bfb904527ebcdc364a59295e538($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
}
}
<?php
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
class Google_Service_Gmail_AutoForwarding extends Google_Model
{
public $disposition;
public $emailAddress;
public $enabled;
public function setDisposition($disposition)
{
$this->disposition = $disposition;
}
public function getDisposition()
{
return $this->disposition;
}
public function setEmailAddress($emailAddress)
{
$this->emailAddress = $emailAddress;
}
public function getEmailAddress()
{
return $this->emailAddress;
}
public function setEnabled($enabled)
{
$this->enabled = $enabled;
}
public function getEnabled()
{
return $this->enabled;
}
}
<?php
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
class Google_Service_Gmail_BatchDeleteMessagesRequest extends Google_Collection
{
protected $collection_key = 'ids';
public $ids;
public function setIds($ids)
{
$this->ids = $ids;
}
public function getIds()
{
return $this->ids;
}
}
<?php
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
class Google_Service_Gmail_BatchModifyMessagesRequest extends Google_Collection
{
protected $collection_key = 'removeLabelIds';
public $addLabelIds;
public $ids;
public $removeLabelIds;
public function setAddLabelIds($addLabelIds)
{
$this->addLabelIds = $addLabelIds;
}
public function getAddLabelIds()
{
return $this->addLabelIds;
}
public function setIds($ids)
{
$this->ids = $ids;
}
public function getIds()
{
return $this->ids;
}
public function setRemoveLabelIds($removeLabelIds)
{
$this->removeLabelIds = $removeLabelIds;
}
public function getRemoveLabelIds()
{
return $this->removeLabelIds;
}
}
<?php
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
class Google_Service_Gmail_Draft extends Google_Model
{
public $id;
protected $messageType = 'Google_Service_Gmail_Message';
protected $messageDataType = '';
public function setId($id)
{
$this->id = $id;
}
public function getId()
{
return $this->id;
}
/**
* @param Google_Service_Gmail_Message
*/
public function setMessage(Google_Service_Gmail_Message $message)
{
$this->message = $message;
}
/**
* @return Google_Service_Gmail_Message
*/
public function getMessage()
{
return $this->message;
}
}
<?php
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
class Google_Service_Gmail_Filter extends Google_Model
{
protected $actionType = 'Google_Service_Gmail_FilterAction';
protected $actionDataType = '';
protected $criteriaType = 'Google_Service_Gmail_FilterCriteria';
protected $criteriaDataType = '';
public $id;
/**
* @param Google_Service_Gmail_FilterAction
*/
public function setAction(Google_Service_Gmail_FilterAction $action)
{
$this->action = $action;
}
/**
* @return Google_Service_Gmail_FilterAction
*/
public function getAction()
{
return $this->action;
}
/**
* @param Google_Service_Gmail_FilterCriteria
*/
public function setCriteria(Google_Service_Gmail_FilterCriteria $criteria)
{
$this->criteria = $criteria;
}
/**
* @return Google_Service_Gmail_FilterCriteria
*/
public function getCriteria()
{
return $this->criteria;
}
public function setId($id)
{
$this->id = $id;
}
public function getId()
{
return $this->id;
}
}
<?php
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
class Google_Service_Gmail_FilterAction extends Google_Collection
{
protected $collection_key = 'removeLabelIds';
public $addLabelIds;
public $forward;
public $removeLabelIds;
public function setAddLabelIds($addLabelIds)
{
$this->addLabelIds = $addLabelIds;
}
public function getAddLabelIds()
{
return $this->addLabelIds;
}
public function setForward($forward)
{
$this->forward = $forward;
}
public function getForward()
{
return $this->forward;
}
public function setRemoveLabelIds($removeLabelIds)
{
$this->removeLabelIds = $removeLabelIds;
}
public function getRemoveLabelIds()
{
return $this->removeLabelIds;
}
}
<?php
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
class Google_Service_Gmail_FilterCriteria extends Google_Model
{
public $excludeChats;
public $from;
public $hasAttachment;
public $negatedQuery;
public $query;
public $size;
public $sizeComparison;
public $subject;
public $to;
public function setExcludeChats($excludeChats)
{
$this->excludeChats = $excludeChats;
}
public function getExcludeChats()
{
return $this->excludeChats;
}
public function setFrom($from)
{
$this->from = $from;
}
public function getFrom()
{
return $this->from;
}
public function setHasAttachment($hasAttachment)
{
$this->hasAttachment = $hasAttachment;
}
public function getHasAttachment()
{
return $this->hasAttachment;
}
public function setNegatedQuery($negatedQuery)
{
$this->negatedQuery = $negatedQuery;
}
public function getNegatedQuery()
{
return $this->negatedQuery;
}
public function setQuery($query)
{
$this->query = $query;
}
public function getQuery()
{
return $this->query;
}
public function setSize($size)
{
$this->size = $size;
}
public function getSize()
{
return $this->size;
}
public function setSizeComparison($sizeComparison)
{
$this->sizeComparison = $sizeComparison;
}
public function getSizeComparison()
{
return $this->sizeComparison;
}
public function setSubject($subject)
{
$this->subject = $subject;
}
public function getSubject()
{
return $this->subject;
}
public function setTo($to)
{
$this->to = $to;
}
public function getTo()
{
return $this->to;
}
}
<?php
/*
* Copyright 2014 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
class Google_Service_Gmail_ForwardingAddress extends Google_Model
{
public $forwardingEmail;
public $verificationStatus;
public function setForwardingEmail($forwardingEmail)
{
$this->forwardingEmail = $forwardingEmail;
}
public function getForwardingEmail()
{
return $this->forwardingEmail;
}
public function setVerificationStatus($verificationStatus)
{
$this->verificationStatus = $verificationStatus;
}
public function getVerificationStatus()
{
return $this->verificationStatus;
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment