no wp
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\AmazonSES;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* AmazonSES Options constructor.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/aws.svg',
|
||||
'slug' => 'amazonses',
|
||||
'title' => esc_html__( 'Amazon SES', 'wp-mail-smtp' ),
|
||||
'disabled' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
?>
|
||||
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading">
|
||||
<p>
|
||||
<?php esc_html_e( 'We\'re sorry, the Amazon SES mailer is not available on your plan. Please upgrade to the PRO plan to unlock all these awesome features.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -1,245 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Options;
|
||||
|
||||
/**
|
||||
* Class AuthAbstract.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class AuthAbstract implements AuthInterface {
|
||||
|
||||
/**
|
||||
* The Connection object.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @var ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* The connection options object.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @var Options
|
||||
*/
|
||||
protected $connection_options;
|
||||
|
||||
/**
|
||||
* Mailer DB options.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mailer_slug = '';
|
||||
|
||||
/**
|
||||
* Key for a stored unique state value.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $state_key = 'wp_mail_smtp_provider_client_state';
|
||||
|
||||
/**
|
||||
* Auth constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $connection = null ) {
|
||||
|
||||
if ( ! is_null( $connection ) ) {
|
||||
$this->connection = $connection;
|
||||
} else {
|
||||
$this->connection = wp_mail_smtp()->get_connections_manager()->get_primary_connection();
|
||||
}
|
||||
|
||||
$this->connection_options = $this->connection->get_options();
|
||||
$this->mailer_slug = $this->connection->get_mailer_slug();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the composer autoloader to include the auth library and all dependencies.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function include_vendor_lib() {
|
||||
|
||||
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update auth code in our DB.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $code
|
||||
*/
|
||||
protected function update_auth_code( $code ) {
|
||||
|
||||
$all = $this->connection_options->get_all();
|
||||
|
||||
// To save in DB.
|
||||
$all[ $this->mailer_slug ]['auth_code'] = $code;
|
||||
|
||||
// To save in currently retrieved options array.
|
||||
$this->options['auth_code'] = $code;
|
||||
|
||||
// NOTE: These options need to be saved by overwriting all options, because WP automatic updates can cause an issue: GH #575!
|
||||
$this->connection_options->set( $all, false, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Setup Wizard flag in our DB.
|
||||
*
|
||||
* @since 2.6.0
|
||||
*
|
||||
* @param boolean $state A state (true/false) to set the is_setup_wizard_auth mailer setting.
|
||||
*/
|
||||
public function update_is_setup_wizard_auth( $state ) {
|
||||
|
||||
$all = $this->connection_options->get_all();
|
||||
|
||||
// To save in DB.
|
||||
$all[ $this->mailer_slug ]['is_setup_wizard_auth'] = (bool) $state;
|
||||
|
||||
// To save in currently retrieved options array.
|
||||
$this->options['is_setup_wizard_auth'] = (bool) $state;
|
||||
|
||||
// NOTE: These options need to be saved by overwriting all options, because WP automatic updates can cause an issue: GH #575!
|
||||
$this->connection_options->set( $all, false, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update access token in our DB.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param mixed $token
|
||||
*/
|
||||
protected function update_access_token( $token ) {
|
||||
|
||||
$all = $this->connection_options->get_all();
|
||||
|
||||
// To save in DB.
|
||||
$all[ $this->mailer_slug ]['access_token'] = $token;
|
||||
|
||||
// To save in currently retrieved options array.
|
||||
$this->options['access_token'] = $token;
|
||||
|
||||
// NOTE: These options need to be saved by overwriting all options, because WP automatic updates can cause an issue: GH #575!
|
||||
$this->connection_options->set( $all, false, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update refresh token in our DB.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param mixed $token
|
||||
*/
|
||||
protected function update_refresh_token( $token ) {
|
||||
|
||||
$all = $this->connection_options->get_all();
|
||||
|
||||
// To save in DB.
|
||||
$all[ $this->mailer_slug ]['refresh_token'] = $token;
|
||||
|
||||
// To save in currently retrieved options array.
|
||||
$this->options['refresh_token'] = $token;
|
||||
|
||||
// NOTE: These options need to be saved by overwriting all options, because WP automatic updates can cause an issue: GH #575!
|
||||
$this->connection_options->set( $all, false, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update access token scopes in our DB.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param array $scopes Scopes array.
|
||||
*/
|
||||
protected function update_scopes( $scopes ) {
|
||||
|
||||
$all = $this->connection_options->get_all();
|
||||
|
||||
// To save in DB.
|
||||
$all[ $this->mailer_slug ]['scopes'] = $scopes;
|
||||
|
||||
// To save in currently retrieved options array.
|
||||
$this->options['scopes'] = $scopes;
|
||||
|
||||
// NOTE: These options need to be saved by overwriting all options, because WP automatic updates can cause an issue: GH #575!
|
||||
$this->connection_options->set( $all, false, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get state value that should be used for `state` parameter in OAuth authorization request.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_state() {
|
||||
|
||||
$state = [
|
||||
wp_create_nonce( $this->state_key ),
|
||||
$this->connection->get_id(),
|
||||
];
|
||||
|
||||
return implode( '-', $state );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_clients_saved() {
|
||||
|
||||
return ! empty( $this->options['client_id'] ) && ! empty( $this->options['client_secret'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_auth_required() {
|
||||
|
||||
return empty( $this->options['access_token'] ) || empty( $this->options['refresh_token'] );
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
/**
|
||||
* Interface AuthInterface.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
interface AuthInterface {
|
||||
|
||||
/**
|
||||
* Whether user saved Client ID/App ID and Client Secret/App Password or not.
|
||||
* Both options are required.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_clients_saved();
|
||||
|
||||
/**
|
||||
* Whether we have an access and refresh tokens or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_auth_required();
|
||||
}
|
||||
@@ -1,547 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Gmail;
|
||||
|
||||
use Exception;
|
||||
use WPMailSMTP\Admin\Area;
|
||||
use WPMailSMTP\Admin\ConnectionSettings;
|
||||
use WPMailSMTP\Admin\DebugEvents\DebugEvents;
|
||||
use WPMailSMTP\Admin\SetupWizard;
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\Providers\AuthAbstract;
|
||||
use WPMailSMTP\Vendor\Google_Client;
|
||||
use WPMailSMTP\Vendor\Google\Service\Gmail;
|
||||
|
||||
/**
|
||||
* Class Auth to request access and refresh tokens.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Auth extends AuthAbstract {
|
||||
|
||||
/**
|
||||
* List of all possible "from email" email addresses (aliases).
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
* @var null|array
|
||||
*/
|
||||
private $aliases = null;
|
||||
|
||||
/**
|
||||
* Auth constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $connection = null ) {
|
||||
|
||||
parent::__construct( $connection );
|
||||
|
||||
if ( $this->mailer_slug !== Options::SLUG ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->options = $this->connection_options->get_group( $this->mailer_slug );
|
||||
|
||||
if ( $this->is_clients_saved() ) {
|
||||
|
||||
$this->include_vendor_lib();
|
||||
|
||||
$this->client = $this->get_client();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url, that users will be redirected back to finish the OAuth process.
|
||||
*
|
||||
* @since 1.5.2 Returned to the old, pre-1.5, structure of the link to preserve BC.
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_plugin_auth_url( $connection = null ) {
|
||||
|
||||
if ( is_null( $connection ) ) {
|
||||
$connection = wp_mail_smtp()->get_connections_manager()->get_primary_connection();
|
||||
}
|
||||
|
||||
$auth_url = apply_filters(
|
||||
'wp_mail_smtp_gmail_get_plugin_auth_url',
|
||||
add_query_arg(
|
||||
[
|
||||
'page' => Area::SLUG,
|
||||
'tab' => 'auth',
|
||||
],
|
||||
admin_url( 'options-general.php' )
|
||||
)
|
||||
);
|
||||
|
||||
return add_query_arg( 'state', self::get_state_param( $connection ), $auth_url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init and get the Google Client object.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.5.0 Add ability to apply custom options to the client via a filter.
|
||||
*
|
||||
* @param bool $force If the client should be forcefully reinitialized.
|
||||
*
|
||||
* @return Google_Client
|
||||
*/
|
||||
public function get_client( $force = false ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
|
||||
|
||||
// Doesn't load client twice + gives ability to overwrite.
|
||||
if ( ! empty( $this->client ) && ! $force ) {
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
$this->include_vendor_lib();
|
||||
|
||||
$client = new Google_Client(
|
||||
array(
|
||||
'client_id' => $this->options['client_id'],
|
||||
'client_secret' => $this->options['client_secret'],
|
||||
'redirect_uris' => array(
|
||||
self::get_oauth_redirect_url(),
|
||||
),
|
||||
)
|
||||
);
|
||||
$client->setApplicationName( 'WP Mail SMTP v' . WPMS_PLUGIN_VER );
|
||||
$client->setAccessType( 'offline' );
|
||||
$client->setPrompt( 'consent' );
|
||||
$client->setIncludeGrantedScopes( false );
|
||||
// We request only the sending capability, as it's what we only need to do.
|
||||
$client->setScopes( array( Gmail::MAIL_GOOGLE_COM ) );
|
||||
$client->setRedirectUri( self::get_oauth_redirect_url() );
|
||||
|
||||
if ( self::use_self_oauth_redirect_url() ) {
|
||||
$client->setState( self::get_state_param( $this->connection ) );
|
||||
} else {
|
||||
$client->setState( self::get_plugin_auth_url( $this->connection ) );
|
||||
}
|
||||
|
||||
// Apply custom options to the client.
|
||||
$client = apply_filters( 'wp_mail_smtp_providers_gmail_auth_get_client_custom_options', $client );
|
||||
|
||||
if (
|
||||
$this->is_auth_required() &&
|
||||
! empty( $this->options['auth_code'] )
|
||||
) {
|
||||
try {
|
||||
$creds = $client->fetchAccessTokenWithAuthCode( $this->options['auth_code'] );
|
||||
} catch ( Exception $e ) {
|
||||
$creds['error'] = $e->getMessage();
|
||||
}
|
||||
|
||||
// Bail if we have an error.
|
||||
if ( ! empty( $creds['error'] ) ) {
|
||||
if ( $creds['error'] === 'invalid_client' ) {
|
||||
$creds['error'] .= PHP_EOL . esc_html__( 'Please make sure your Google Client ID and Secret in the plugin settings are valid. Save the settings and try the Authorization again.' , 'wp-mail-smtp' );
|
||||
}
|
||||
|
||||
Debug::set(
|
||||
'Mailer: Gmail' . "\r\n" .
|
||||
$creds['error']
|
||||
);
|
||||
|
||||
return $client;
|
||||
} else {
|
||||
Debug::clear();
|
||||
}
|
||||
|
||||
$this->update_access_token( $client->getAccessToken() );
|
||||
$this->update_refresh_token( $client->getRefreshToken() );
|
||||
$this->update_user_details( $client );
|
||||
|
||||
// Update the "from email" to the connected user's email.
|
||||
if ( ! empty( $this->options['user_details']['email'] ) ) {
|
||||
$this->connection_options->set(
|
||||
[
|
||||
'mail' => [
|
||||
'from_email' => $this->options['user_details']['email'],
|
||||
],
|
||||
],
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $this->options['access_token'] ) ) {
|
||||
$client->setAccessToken( $this->options['access_token'] );
|
||||
}
|
||||
|
||||
// Refresh the token if it's expired.
|
||||
if ( $client->isAccessTokenExpired() ) {
|
||||
$refresh = $client->getRefreshToken();
|
||||
if ( empty( $refresh ) && isset( $this->options['refresh_token'] ) ) {
|
||||
$refresh = $this->options['refresh_token'];
|
||||
}
|
||||
|
||||
if ( ! empty( $refresh ) ) {
|
||||
try {
|
||||
$creds = $client->fetchAccessTokenWithRefreshToken( $refresh );
|
||||
} catch ( Exception $e ) {
|
||||
$creds['error'] = $e->getMessage();
|
||||
Debug::set(
|
||||
'Mailer: Gmail' . "\r\n" .
|
||||
$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() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
|
||||
|
||||
$redirect_url = ( new ConnectionSettings( $this->connection ) )->get_admin_page_url();
|
||||
$is_setup_wizard_auth = ! empty( $this->options['is_setup_wizard_auth'] );
|
||||
|
||||
if ( $is_setup_wizard_auth ) {
|
||||
$this->update_is_setup_wizard_auth( false );
|
||||
|
||||
$redirect_url = SetupWizard::get_site_url() . '#/step/configure_mailer/gmail';
|
||||
}
|
||||
|
||||
if ( ! ( isset( $_GET['tab'] ) && $_GET['tab'] === 'auth' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
wp_safe_redirect( $redirect_url );
|
||||
exit;
|
||||
}
|
||||
|
||||
$state = isset( $_GET['state'] ) ? sanitize_key( $_GET['state'] ) : false;
|
||||
|
||||
if ( empty( $state ) ) {
|
||||
wp_safe_redirect(
|
||||
add_query_arg( 'error', 'oauth_invalid_state', $redirect_url )
|
||||
);
|
||||
}
|
||||
|
||||
list( $nonce ) = array_pad( explode( '-', $state ), 1, false );
|
||||
|
||||
// Verify the nonce that should be returned in the state parameter.
|
||||
if ( ! wp_verify_nonce( $nonce, $this->state_key ) ) {
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
'error',
|
||||
'google_invalid_nonce',
|
||||
$redirect_url
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
// We can't process without saved client_id/secret.
|
||||
if ( ! $this->is_clients_saved() ) {
|
||||
Debug::set(
|
||||
esc_html__( '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-mail-smtp' )
|
||||
);
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
'error',
|
||||
'google_no_clients',
|
||||
$redirect_url
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->include_vendor_lib();
|
||||
|
||||
$code = '';
|
||||
$scope = '';
|
||||
$error = '';
|
||||
|
||||
if ( isset( $_GET['error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$error = sanitize_key( $_GET['error'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
}
|
||||
|
||||
// In case of any error: display a message to a user.
|
||||
if ( ! empty( $error ) ) {
|
||||
DebugEvents::add_debug(
|
||||
sprintf( /* Translators: %s the error code passed from Google. */
|
||||
esc_html__( 'There was an error while processing Google authorization: %s' ),
|
||||
esc_html( $error )
|
||||
)
|
||||
);
|
||||
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
'error',
|
||||
'google_' . $error,
|
||||
$redirect_url
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( isset( $_GET['code'] ) ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
$code = urldecode( $_GET['code'] );
|
||||
}
|
||||
|
||||
if ( isset( $_GET['scope'] ) ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
$scope = $_GET['scope'];
|
||||
|
||||
if ( self::use_self_oauth_redirect_url() ) {
|
||||
$scope = urldecode( $scope );
|
||||
} else {
|
||||
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
|
||||
$scope = urldecode( base64_decode( $scope ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Let's try to get the access token.
|
||||
if (
|
||||
! empty( $code ) &&
|
||||
(
|
||||
$scope === Gmail::MAIL_GOOGLE_COM . ' ' . Gmail::GMAIL_SEND ||
|
||||
$scope === Gmail::GMAIL_SEND . ' ' . Gmail::MAIL_GOOGLE_COM ||
|
||||
$scope === Gmail::GMAIL_SEND ||
|
||||
$scope === Gmail::MAIL_GOOGLE_COM
|
||||
)
|
||||
) {
|
||||
// Save the auth code. So Google_Client can reuse it to retrieve the access token.
|
||||
$this->update_auth_code( $code );
|
||||
} else {
|
||||
DebugEvents::add_debug(
|
||||
esc_html__( 'There was an error while processing Google authorization: missing code or scope parameter.' )
|
||||
);
|
||||
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
'error',
|
||||
'google_no_code_scope',
|
||||
$redirect_url
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
Debug::clear();
|
||||
|
||||
$this->get_client( true );
|
||||
|
||||
$error = Debug::get_last();
|
||||
|
||||
if ( ! empty( $error ) ) {
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
'error',
|
||||
'google_unsuccessful_oauth',
|
||||
$redirect_url
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
'success',
|
||||
'google_site_linked',
|
||||
$redirect_url
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the auth URL used to proceed to Provider to request access to send emails.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_auth_url() {
|
||||
|
||||
if (
|
||||
! empty( $this->client ) &&
|
||||
class_exists( 'WPMailSMTP\Vendor\Google_Client', false ) &&
|
||||
$this->client instanceof Google_Client
|
||||
) {
|
||||
return filter_var( $this->client->createAuthUrl(), FILTER_SANITIZE_URL );
|
||||
}
|
||||
|
||||
return '#';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and update user-related details (currently only email).
|
||||
*
|
||||
* @since 3.11.0
|
||||
*
|
||||
* @param Google_Client $client The Google Client object (optional).
|
||||
*/
|
||||
private function update_user_details( $client = false ) {
|
||||
|
||||
if ( $client === false ) {
|
||||
$client = $this->get_client();
|
||||
}
|
||||
|
||||
$gmail = new Gmail( $client );
|
||||
|
||||
try {
|
||||
$email = $gmail->users->getProfile( 'me' )->getEmailAddress();
|
||||
|
||||
$user_details = [
|
||||
'email' => $email,
|
||||
];
|
||||
|
||||
// To save in DB.
|
||||
$updated_settings = [
|
||||
$this->mailer_slug => [
|
||||
'user_details' => $user_details,
|
||||
],
|
||||
];
|
||||
|
||||
// To save in currently retrieved options array.
|
||||
$this->options['user_details'] = $user_details;
|
||||
|
||||
$this->connection_options->set( $updated_settings, false, false );
|
||||
} catch ( Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user information (currently only email) that is associated with the current OAuth connection.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 3.11.0 Switched to DB stored value instead of API call.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_user_info() {
|
||||
|
||||
/*
|
||||
* We need to populate user data on the fly for old users who already performed
|
||||
* authorization before we switched to DB stored value.
|
||||
*/
|
||||
if ( ! isset( $this->options['user_details'] ) && ! $this->is_auth_required() ) {
|
||||
$this->update_user_details();
|
||||
}
|
||||
|
||||
return $this->connection_options->get( $this->mailer_slug, 'user_details' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the registered email addresses that the user can use as the "from email".
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
* @return array The list of possible from email addresses.
|
||||
*/
|
||||
public function get_user_possible_send_from_addresses() {
|
||||
|
||||
if ( isset( $this->aliases ) ) {
|
||||
return $this->aliases;
|
||||
}
|
||||
|
||||
$gmail = new Gmail( $this->get_client() );
|
||||
|
||||
try {
|
||||
|
||||
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||
$response = $gmail->users_settings_sendAs->listUsersSettingsSendAs( 'me' );
|
||||
|
||||
// phpcs:disable
|
||||
$this->aliases = array_map(
|
||||
function( $sendAsObject ) {
|
||||
return $sendAsObject['sendAsEmail'];
|
||||
},
|
||||
(array) $response->getSendAs()
|
||||
);
|
||||
// phpcs:enable
|
||||
|
||||
} catch ( Exception $exception ) {
|
||||
DebugEvents::add_debug(
|
||||
sprintf( /* Translators: %s the error message. */
|
||||
esc_html__( 'An error occurred when trying to get Gmail aliases: %s' ),
|
||||
esc_html( $exception->getMessage() )
|
||||
)
|
||||
);
|
||||
|
||||
$this->aliases = [];
|
||||
}
|
||||
|
||||
return $this->aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Google oAuth 2.0 redirect URL.
|
||||
*
|
||||
* This is the URL that Google will redirect after the access to the Gmail account is granted or rejected.
|
||||
* The below endpoint will then redirect back to the user's WP site (to self::get_plugin_auth_url() URL).
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_oauth_redirect_url() {
|
||||
|
||||
if ( self::use_self_oauth_redirect_url() ) {
|
||||
return remove_query_arg( 'state', self::get_plugin_auth_url() );
|
||||
} else {
|
||||
return 'https://connect.wpmailsmtp.com/google/';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the state parameter for the Google oAuth redirect URL.
|
||||
*
|
||||
* @since 3.10.0
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function get_state_param( $connection ) {
|
||||
|
||||
$state = [
|
||||
wp_create_nonce( 'wp_mail_smtp_provider_client_state' ),
|
||||
$connection->get_id(),
|
||||
];
|
||||
|
||||
return implode( '-', $state );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to use self website redirect URL for the Google oAuth.
|
||||
*
|
||||
* @since 3.10.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function use_self_oauth_redirect_url() {
|
||||
|
||||
/**
|
||||
* Filter whether to use self website redirect URL for the Google oAuth.
|
||||
*
|
||||
* @since 3.10.0
|
||||
*
|
||||
* @param bool $use Whether to use self website redirect URL for the Google oAuth.
|
||||
*/
|
||||
return apply_filters( 'wp_mail_smtp_providers_gmail_auth_use_self_oauth_redirect_url', false );
|
||||
}
|
||||
}
|
||||
@@ -1,294 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Gmail;
|
||||
|
||||
use WPMailSMTP\Admin\DebugEvents\DebugEvents;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\MailCatcherInterface;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
use WPMailSMTP\Vendor\Google\Service\Gmail;
|
||||
use WPMailSMTP\Vendor\Google\Service\Gmail\Message;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://www.googleapis.com/upload/gmail/v1/users/{userId}/messages/send';
|
||||
|
||||
/**
|
||||
* Gmail message.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var Message
|
||||
*/
|
||||
protected $message;
|
||||
|
||||
/**
|
||||
* Re-use the MailCatcher class methods and properties.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @param MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
*/
|
||||
public function process_phpmailer( $phpmailer ) {
|
||||
|
||||
// Make sure that we have access to PHPMailer class methods.
|
||||
if ( ! wp_mail_smtp()->is_valid_phpmailer( $phpmailer ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->phpmailer = $phpmailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use Google API Services to send emails.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function send() {
|
||||
|
||||
// Include the Google library.
|
||||
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
|
||||
|
||||
$auth = new Auth( $this->connection );
|
||||
$message = new Message();
|
||||
|
||||
// Set the authorized Gmail email address as the "from email" if the set email is not on the list of aliases.
|
||||
$possible_from_emails = $auth->get_user_possible_send_from_addresses();
|
||||
|
||||
if ( ! in_array( $this->phpmailer->From, $possible_from_emails, true ) ) {
|
||||
$user_info = $auth->get_user_info();
|
||||
|
||||
if ( ! empty( $user_info['email'] ) ) {
|
||||
$this->phpmailer->From = $user_info['email'];
|
||||
$this->phpmailer->Sender = $user_info['email'];
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Prepare a message for sending if any changes happened above.
|
||||
$this->phpmailer->preSend();
|
||||
|
||||
// Get the raw MIME email using MailCatcher data. We need to make base64URL-safe string.
|
||||
$base64 = str_replace(
|
||||
[ '+', '/', '=' ],
|
||||
[ '-', '_', '' ],
|
||||
base64_encode( $this->phpmailer->getSentMIMEMessage() ) //phpcs:ignore
|
||||
);
|
||||
|
||||
$message->setRaw( $base64 );
|
||||
|
||||
$service = new Gmail( $auth->get_client() );
|
||||
$response = $service->users_messages->send( 'me', $message );
|
||||
|
||||
DebugEvents::add_debug(
|
||||
esc_html__( 'An email request was sent to the Gmail API.', 'wp-mail-smtp' )
|
||||
);
|
||||
|
||||
$this->process_response( $response );
|
||||
} catch ( \Exception $e ) {
|
||||
$this->error_message = $this->process_exception_message( $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save response from the API to use it later.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.5.0 Added action "wp_mail_smtp_providers_gmail_mailer_process_response" with $response.
|
||||
*
|
||||
* @param Message $response Instance of Gmail response.
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
$this->response = $response;
|
||||
|
||||
if ( empty( $this->response ) || ! method_exists( $this->response, 'getId' ) ) {
|
||||
$this->error_message = esc_html__( 'The response object is invalid (missing getId method).', 'wp-mail-smtp' );
|
||||
} else {
|
||||
$message_id = $this->response->getId();
|
||||
|
||||
if ( empty( $message_id ) ) {
|
||||
$this->error_message = esc_html__( 'The email message ID is missing.', 'wp-mail-smtp' );
|
||||
}
|
||||
}
|
||||
|
||||
do_action( 'wp_mail_smtp_providers_gmail_mailer_process_response', $this->response, $this->phpmailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the email was sent.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_email_sent() {
|
||||
|
||||
$is_sent = false;
|
||||
|
||||
if (
|
||||
! empty( $this->response ) &&
|
||||
method_exists( $this->response, 'getId' ) &&
|
||||
! empty( $this->response->getId() )
|
||||
) {
|
||||
$is_sent = true;
|
||||
}
|
||||
|
||||
/** This filter is documented in src/Providers/MailerAbstract.php. */
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_is_email_sent', $is_sent, $this->mailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
|
||||
|
||||
$gmail_text = array();
|
||||
|
||||
$gmail = $this->connection_options->get_group( 'gmail' );
|
||||
$curl_ver = 'No';
|
||||
if ( function_exists( 'curl_version' ) ) {
|
||||
$curl = curl_version();
|
||||
$curl_ver = $curl['version'];
|
||||
}
|
||||
|
||||
$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' ) && defined( 'OPENSSL_VERSION_TEXT' ) ? OPENSSL_VERSION_TEXT : '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> ' . $curl_ver;
|
||||
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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the mailer has all its settings correctly set up and saved.
|
||||
*
|
||||
* @since 1.4.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
if ( ! $this->is_php_compatible() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$auth = new Auth( $this->connection );
|
||||
|
||||
if (
|
||||
$auth->is_clients_saved() &&
|
||||
! $auth->is_auth_required()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the exception message and append additional explanation to it.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @param mixed $message A string or an object with strings.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function process_exception_message( $message ) {
|
||||
|
||||
// Transform the passed message to a string.
|
||||
if ( ! is_string( $message ) ) {
|
||||
$message = wp_json_encode( $message );
|
||||
} else {
|
||||
$message = wp_strip_all_tags( $message, false );
|
||||
}
|
||||
|
||||
// Define known errors, that we will scan the message with.
|
||||
$known_errors = [
|
||||
[
|
||||
'errors' => [
|
||||
'invalid_grant',
|
||||
],
|
||||
'explanation' => esc_html__( 'Please re-grant Google app permissions!', 'wp-mail-smtp' ) . ' ' . WP::EOL .
|
||||
esc_html__( 'Go to WP Mail SMTP plugin settings page. Click the “Remove OAuth Connection” button.', 'wp-mail-smtp' ) . ' ' . WP::EOL .
|
||||
esc_html__( 'Then click the “Allow plugin to send emails using your Google account” button and re-enable access.', 'wp-mail-smtp' ),
|
||||
],
|
||||
];
|
||||
|
||||
// Check if we get a match and append the explanation to the original message.
|
||||
foreach ( $known_errors as $error ) {
|
||||
foreach ( $error['errors'] as $error_fragment ) {
|
||||
if ( false !== strpos( $message, $error_fragment ) ) {
|
||||
return Helpers::format_error_message( $message, '', $error['explanation'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we get no match we return the original message (as a string).
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default email addresses for the reply to email parameter.
|
||||
*
|
||||
* @deprecated 2.1.1
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @since 2.1.1 Not used anymore.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function default_reply_to_addresses() {
|
||||
|
||||
_deprecated_function( __CLASS__ . '::' . __METHOD__, '2.1.1 of WP Mail SMTP plugin' );
|
||||
|
||||
$gmail_creds = ( new Auth( $this->connection ) )->get_user_info();
|
||||
|
||||
if ( empty( $gmail_creds['email'] ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
$gmail_creds['email'] => [
|
||||
$gmail_creds['email'],
|
||||
'',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,291 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Gmail;
|
||||
|
||||
use WPMailSMTP\Admin\ConnectionSettings;
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Helpers\UI;
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Option.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
const SLUG = 'gmail';
|
||||
|
||||
/**
|
||||
* Gmail Options constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 2.3.0 Added supports parameter.
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $connection = null ) {
|
||||
|
||||
parent::__construct(
|
||||
[
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/google.svg',
|
||||
'slug' => self::SLUG,
|
||||
'title' => esc_html__( 'Google / Gmail', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses( /* translators: %s - URL to our Gmail doc. */
|
||||
__( 'Our Gmail mailer works with any Gmail or Google Workspace account via the Google API. You can send WordPress emails from your main email address or a Gmail alias, and it\'s more secure than connecting to Gmail using SMTP credentials. We now have a One-Click Setup, which simply asks you to authorize your Google account to use our app and takes care of everything for you. Alternatively, you can connect manually, which involves several steps that are more technical than other mailer options, so we created a detailed guide to walk you through the process.<br><br>To get started, read our <a href="%s" target="_blank" rel="noopener noreferrer">Gmail documentation</a>.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'br' => [],
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
),
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-gmail-mailer-in-wp-mail-smtp/', 'Gmail documentation' ) )
|
||||
),
|
||||
'notices' => [
|
||||
'educational' => wp_kses(
|
||||
__( 'The Gmail mailer works well for sites that send low numbers of emails. However, Gmail\'s API has rate limitations and a number of additional restrictions that can lead to challenges during setup.<br><br>If you expect to send a high volume of emails, or if you find that your web host is not compatible with the Gmail API restrictions, then we recommend considering a different mailer option.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'br' => [],
|
||||
]
|
||||
),
|
||||
],
|
||||
'php' => '5.6',
|
||||
'supports' => [
|
||||
'from_email' => true,
|
||||
'from_name' => true,
|
||||
'return_path' => false,
|
||||
'from_email_force' => true,
|
||||
'from_name_force' => true,
|
||||
],
|
||||
],
|
||||
$connection
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if ( ! wp_mail_smtp()->is_pro() ) : ?>
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-one_click_setup_enabled-lite" class="wp-mail-smtp-setting-row">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-one_click_setup_enabled-lite">
|
||||
<?php esc_html_e( 'One-Click Setup', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php
|
||||
UI::toggle(
|
||||
[
|
||||
'id' => 'wp-mail-smtp-setting-' . esc_attr( $this->get_slug() ) . '-one_click_setup_enabled-lite',
|
||||
]
|
||||
);
|
||||
?>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'Provides a quick and easy way to connect to Google that doesn\'t require creating your own app.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- 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->connection_options->get( $this->get_slug(), 'client_id' ) ); ?>"
|
||||
<?php echo $this->connection_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">
|
||||
<?php if ( $this->connection_options->is_const_defined( $this->get_slug(), 'client_secret' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_GMAIL_CLIENT_SECRET' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][client_secret]"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'client_secret' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
</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" onfocus="this.select();"
|
||||
value="<?php echo esc_attr( Auth::get_oauth_redirect_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-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( 'Please copy this URL into the "Authorized redirect URIs" field of your Google web application.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Auth users button -->
|
||||
<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( 'Authorization', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php $this->display_auth_setting_action(); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display either an "Allow..." or "Remove..." button.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
protected function display_auth_setting_action() {
|
||||
|
||||
// Do the processing on the fly, as having ajax here is too complicated.
|
||||
$this->process_provider_remove();
|
||||
|
||||
$auth = new Auth( $this->connection );
|
||||
?>
|
||||
|
||||
<?php if ( $auth->is_clients_saved() ) : ?>
|
||||
|
||||
<?php if ( $auth->is_auth_required() ) : ?>
|
||||
|
||||
<a href="<?php echo esc_url( $auth->get_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>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<a href="<?php echo esc_url( wp_nonce_url( ( new ConnectionSettings( $this->connection ) )->get_admin_page_url(), 'gmail_remove', 'gmail_remove_nonce' ) ); ?>#wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-authorize" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-red js-wp-mail-smtp-provider-remove">
|
||||
<?php esc_html_e( 'Remove OAuth Connection', 'wp-mail-smtp' ); ?>
|
||||
</a>
|
||||
<span class="connected-as">
|
||||
<?php
|
||||
$user = $auth->get_user_info();
|
||||
|
||||
if ( ! empty( $user['email'] ) ) {
|
||||
printf(
|
||||
/* translators: %s - email address, as received from Google API. */
|
||||
esc_html__( 'Connected as %s', 'wp-mail-smtp' ),
|
||||
'<code>' . esc_html( $user['email'] ) . '</code>'
|
||||
);
|
||||
}
|
||||
?>
|
||||
</span>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
wp_kses( /* translators: %s - URL to Google Gmail alias documentation page. */
|
||||
__( 'If you want to use a different From Email address you can set up a Google email alias. <a href="%s" target="_blank" rel="noopener noreferrer">Follow these instructions</a> and then select the From Email at the top of this page.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
),
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/gmail-send-from-alias-wp-mail-smtp/', 'Gmail aliases description - Follow these instructions' ) )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'You can also send emails with different From Email addresses, by disabling the Force From Email setting and using registered aliases throughout your WordPress site as the From Email addresses.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'Removing the OAuth connection will give you an ability to redo the OAuth connection or link to another Google account.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<p class="inline-notice inline-error">
|
||||
<?php esc_html_e( 'You need to save settings with Client ID and Client Secret before you can proceed.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Provider OAuth connection.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public function process_provider_remove() {
|
||||
|
||||
if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
! isset( $_GET['gmail_remove_nonce'] ) ||
|
||||
! wp_verify_nonce( sanitize_key( $_GET['gmail_remove_nonce'] ), 'gmail_remove' )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->connection->get_mailer_slug() !== $this->get_slug() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$old_opt = $this->connection_options->get_all_raw();
|
||||
|
||||
unset( $old_opt[ $this->get_slug() ]['access_token'] );
|
||||
unset( $old_opt[ $this->get_slug() ]['refresh_token'] );
|
||||
unset( $old_opt[ $this->get_slug() ]['user_details'] );
|
||||
unset( $old_opt[ $this->get_slug() ]['auth_code'] );
|
||||
|
||||
$this->connection_options->set( $old_opt );
|
||||
}
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\MailCatcherInterface;
|
||||
use WPMailSMTP\Options;
|
||||
|
||||
/**
|
||||
* Class Loader.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Loader {
|
||||
|
||||
/**
|
||||
* Key is the mailer option, value is the path to its classes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.6.0 Added Sendinblue.
|
||||
* @since 1.7.0 Added AmazonSES/Outlook as indication of the Pro mailers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $providers = [
|
||||
'mail' => 'WPMailSMTP\Providers\Mail\\',
|
||||
'sendlayer' => 'WPMailSMTP\Providers\Sendlayer\\',
|
||||
'smtpcom' => 'WPMailSMTP\Providers\SMTPcom\\',
|
||||
'sendinblue' => 'WPMailSMTP\Providers\Sendinblue\\',
|
||||
'amazonses' => 'WPMailSMTP\Providers\AmazonSES\\',
|
||||
'gmail' => 'WPMailSMTP\Providers\Gmail\\',
|
||||
'mailgun' => 'WPMailSMTP\Providers\Mailgun\\',
|
||||
'outlook' => 'WPMailSMTP\Providers\Outlook\\',
|
||||
'pepipostapi' => 'WPMailSMTP\Providers\PepipostAPI\\',
|
||||
'postmark' => 'WPMailSMTP\Providers\Postmark\\',
|
||||
'sendgrid' => 'WPMailSMTP\Providers\Sendgrid\\',
|
||||
'sparkpost' => 'WPMailSMTP\Providers\SparkPost\\',
|
||||
'zoho' => 'WPMailSMTP\Providers\Zoho\\',
|
||||
'smtp' => 'WPMailSMTP\Providers\SMTP\\',
|
||||
'pepipost' => 'WPMailSMTP\Providers\Pepipost\\',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get all the supported providers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_providers() {
|
||||
|
||||
if ( ! Options::init()->is_mailer_active( 'pepipost' ) ) {
|
||||
unset( $this->providers['pepipost'] );
|
||||
}
|
||||
|
||||
if ( ! Options::init()->is_mailer_active( 'pepipostapi' ) ) {
|
||||
unset( $this->providers['pepipostapi'] );
|
||||
}
|
||||
|
||||
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 string|null
|
||||
*/
|
||||
public function get_provider_path( $provider ) {
|
||||
|
||||
$provider = sanitize_key( $provider );
|
||||
|
||||
$providers = $this->get_providers();
|
||||
|
||||
return apply_filters(
|
||||
'wp_mail_smtp_providers_loader_get_provider_path',
|
||||
isset( $providers[ $provider ] ) ? $providers[ $provider ] : null,
|
||||
$provider
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the provider options, if exists.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $provider
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*
|
||||
* @return OptionsAbstract|null
|
||||
*/
|
||||
public function get_options( $provider, $connection = null ) {
|
||||
|
||||
return $this->get_entity( $provider, 'Options', [ $connection ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all options of all providers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*
|
||||
* @return OptionsAbstract[]
|
||||
*/
|
||||
public function get_options_all( $connection = null ) {
|
||||
|
||||
$options = array();
|
||||
|
||||
foreach ( $this->get_providers() as $provider => $path ) {
|
||||
|
||||
$option = $this->get_options( $provider, $connection );
|
||||
|
||||
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 The provider name.
|
||||
* @param MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*
|
||||
* @return MailerAbstract|null
|
||||
*/
|
||||
public function get_mailer( $provider, $phpmailer, $connection = null ) {
|
||||
|
||||
return $this->get_entity( $provider, 'Mailer', [ $phpmailer, $connection ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the provider auth, if exists.
|
||||
*
|
||||
* @param string $provider
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*
|
||||
* @return AuthAbstract|null
|
||||
*/
|
||||
public function get_auth( $provider, $connection = null ) {
|
||||
|
||||
return $this->get_entity( $provider, 'Auth', [ $connection ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a generic entity based on the request.
|
||||
*
|
||||
* @uses \ReflectionClass
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $provider
|
||||
* @param string $request
|
||||
* @param array $args Entity instantiation arguments.
|
||||
*
|
||||
* @return OptionsAbstract|MailerAbstract|AuthAbstract|null
|
||||
*/
|
||||
protected function get_entity( $provider, $request, $args = [] ) {
|
||||
|
||||
$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;
|
||||
$entity = new $class( ...$args );
|
||||
}
|
||||
}
|
||||
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, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supports options for all mailers.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_supports_all() {
|
||||
|
||||
$supports = [];
|
||||
|
||||
foreach ( $this->get_providers() as $provider => $path ) {
|
||||
$option = $this->get_options( $provider );
|
||||
|
||||
if ( ! $option instanceof OptionsAbstract ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$mailer_slug = $option->get_slug();
|
||||
$mailer_supports = $option->get_supports();
|
||||
|
||||
if ( empty( $mailer_slug ) || empty( $mailer_supports ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$supports[ $mailer_slug ] = $mailer_supports;
|
||||
}
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_loader_get_supports_all', $supports );
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Mail;
|
||||
|
||||
use WPMailSMTP\Admin\SetupWizard;
|
||||
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()->assets_url . '/images/providers/php.svg',
|
||||
'slug' => 'mail',
|
||||
'title' => esc_html__( 'Default (none)', 'wp-mail-smtp' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
?>
|
||||
|
||||
<blockquote>
|
||||
<?php
|
||||
printf(
|
||||
wp_kses( /* translators: %1$s - URL to all mailer doc page. %2$s - URL to the setup wizard. */
|
||||
__( 'You currently have the <strong>Default (none)</strong> mailer selected, which won\'t improve email deliverability. Please select <a href="%1$s" target="_blank" rel="noopener noreferrer">any other email provider</a> and use the easy <a href="%2$s">Setup Wizard</a> to configure it.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'strong' => [],
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
),
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/a-complete-guide-to-wp-mail-smtp-mailers/', 'Default mailer - any other email provider' ) ),
|
||||
esc_url( SetupWizard::get_site_url() )
|
||||
);
|
||||
?>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -1,672 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\Admin\DebugEvents\DebugEvents;
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\MailCatcherInterface;
|
||||
use WPMailSMTP\Options;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class MailerAbstract.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class MailerAbstract implements MailerInterface {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var Options
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var MailCatcherInterface
|
||||
*/
|
||||
protected $phpmailer;
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mailer = '';
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = '';
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = array();
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $body = array();
|
||||
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $response = array();
|
||||
|
||||
/**
|
||||
* The error message recorded when email sending failed and the error can't be processed from the API response.
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error_message = '';
|
||||
|
||||
/**
|
||||
* Should the email sent by this mailer have its "sent status" verified via its API?
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $verify_sent_status = false;
|
||||
|
||||
/**
|
||||
* The Connection object.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @var ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* The connection options object.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @var Options
|
||||
*/
|
||||
protected $connection_options;
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( MailCatcherInterface $phpmailer, $connection = null ) {
|
||||
|
||||
if ( ! is_null( $connection ) ) {
|
||||
$this->connection = $connection;
|
||||
} else {
|
||||
$this->connection = wp_mail_smtp()->get_connections_manager()->get_primary_connection();
|
||||
}
|
||||
|
||||
$this->connection_options = $this->connection->get_options();
|
||||
$this->mailer = $this->connection->get_mailer_slug();
|
||||
$this->options = Options::init();
|
||||
|
||||
// Only non-SMTP mailers need URL and extra processing for PHPMailer class.
|
||||
if ( ! $this->connection_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 MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
*/
|
||||
public function process_phpmailer( $phpmailer ) {
|
||||
|
||||
// Make sure that we have access to PHPMailer class methods.
|
||||
if ( ! wp_mail_smtp()->is_valid_phpmailer( $phpmailer ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->phpmailer = $phpmailer;
|
||||
|
||||
// Prevent working with those methods, as they are not needed for SMTP-like mailers.
|
||||
if ( $this->connection_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 );
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$this->set_content( $this->phpmailer->Body );
|
||||
} else {
|
||||
$this->set_content(
|
||||
array(
|
||||
'text' => $this->phpmailer->AltBody,
|
||||
'html' => $this->phpmailer->Body,
|
||||
)
|
||||
);
|
||||
}
|
||||
$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() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the email headers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $headers List of key=>value pairs.
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set individual header key=>value pair for the email.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function set_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
|
||||
$this->headers[ $name ] = WP::sanitize_value( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email subject.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $subject
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the email body.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_get_body', $this->body, $this->mailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the email headers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_headers() {
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_get_headers', $this->headers, $this->mailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the email.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.8.0 Added timeout for requests, same as max_execution_time.
|
||||
*/
|
||||
public function send() {
|
||||
|
||||
$timeout = (int) ini_get( 'max_execution_time' );
|
||||
|
||||
$params = Options::array_merge_recursive(
|
||||
$this->get_default_params(),
|
||||
array(
|
||||
'headers' => $this->get_headers(),
|
||||
'body' => $this->get_body(),
|
||||
'timeout' => $timeout ? $timeout : 30,
|
||||
)
|
||||
);
|
||||
|
||||
$response = wp_safe_remote_post( $this->url, $params );
|
||||
|
||||
DebugEvents::add_debug(
|
||||
esc_html__( 'An email request was sent.', 'wp-mail-smtp' )
|
||||
);
|
||||
|
||||
$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 mixed $response Response array.
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
// Save the error text.
|
||||
foreach ( $response->errors as $error_code => $error_message ) {
|
||||
$this->error_message .= Helpers::format_error_message( $error_message, $error_code ) . WP::EOL;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $response['body'] ) && WP::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,
|
||||
),
|
||||
$this->mailer
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
$is_sent = false;
|
||||
|
||||
if ( wp_remote_retrieve_response_code( $this->response ) === $this->email_sent_code ) {
|
||||
$is_sent = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters whether the email is sent or not.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param bool $is_sent Whether the email is sent or not.
|
||||
* @param MailerAbstract $mailer Mailer object.
|
||||
*/
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_is_email_sent', $is_sent, $this->mailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* The error message when email sending failed.
|
||||
* Should be overwritten when appropriate.
|
||||
*
|
||||
* @since 1.2.0
|
||||
* @since 2.5.0 Return a non-empty error_message attribute.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_response_error() {
|
||||
|
||||
return ! empty( $this->error_message ) ? $this->error_message : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the mailer supports the current PHP version or not.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_php_compatible() {
|
||||
|
||||
$options = wp_mail_smtp()->get_providers()->get_options( $this->mailer, $this->connection );
|
||||
|
||||
return version_compare( phpversion(), $options->get_php_version(), '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->connection_options->is_mailer_smtp() ) {
|
||||
// phpcs:disable
|
||||
$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>' . wp_json_encode( $phpmailer->SMTPOptions ) . '</code>';
|
||||
}
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
$smtp_text[] = '<br><strong>Server:</strong>';
|
||||
$smtp_text[] = '<strong>OpenSSL:</strong> ' . ( extension_loaded( 'openssl' ) && defined( 'OPENSSL_VERSION_TEXT' ) ? OPENSSL_VERSION_TEXT : '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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the email addresses for the reply to email parameter.
|
||||
*
|
||||
* @deprecated 2.1.1
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @since 2.1.1 Not used anymore.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_reply_to_addresses() {
|
||||
|
||||
_deprecated_function( __CLASS__ . '::' . __METHOD__, '2.1.1 of WP Mail SMTP plugin' );
|
||||
|
||||
$reply_to = $this->phpmailer->getReplyToAddresses();
|
||||
|
||||
// Return the passed reply to addresses, if defined.
|
||||
if ( ! empty( $reply_to ) ) {
|
||||
return $reply_to;
|
||||
}
|
||||
|
||||
// Return the default reply to addresses.
|
||||
return apply_filters(
|
||||
'wp_mail_smtp_providers_mailer_default_reply_to_addresses',
|
||||
$this->default_reply_to_addresses()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default email addresses for the reply to email parameter.
|
||||
*
|
||||
* @deprecated 2.1.1
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @since 2.1.1 Not used anymore.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function default_reply_to_addresses() {
|
||||
|
||||
_deprecated_function( __CLASS__ . '::' . __METHOD__, '2.1.1 of WP Mail SMTP plugin' );
|
||||
|
||||
return [
|
||||
$this->phpmailer->From => [
|
||||
$this->phpmailer->From,
|
||||
$this->phpmailer->FromName,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the email sent by this mailer have its "sent status" verified via its API?
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_verify_sent_status() {
|
||||
|
||||
return $this->verify_sent_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the "sent status" of the provided email log ID.
|
||||
* The actual verification background task is triggered in the below action hook.
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @param int $email_log_id The ID of the email log.
|
||||
*/
|
||||
public function verify_sent_status( $email_log_id ) {
|
||||
|
||||
if ( ! $this->should_verify_sent_status() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
do_action( 'wp_mail_smtp_providers_mailer_verify_sent_status', $email_log_id, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name/slug of the current mailer.
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_mailer_name() {
|
||||
|
||||
return $this->mailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PHPMailer attachment file content.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array $attachment PHPMailer attachment.
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
public function get_attachment_file_content( $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 ( $attachment[5] === true ) { // Whether there is string attachment.
|
||||
$file = $attachment[0];
|
||||
} elseif ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
|
||||
$file = file_get_contents( $attachment[0] );
|
||||
}
|
||||
} catch ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
|
||||
// We don't handle this exception as we define a default value above.
|
||||
}
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PHPMailer attachment file size.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param array $attachment PHPMailer attachment.
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
public function get_attachment_file_size( $attachment ) {
|
||||
|
||||
$size = false;
|
||||
|
||||
if ( $attachment[5] === true ) { // Whether there is string attachment.
|
||||
$size = Helpers::strsize( $attachment[0] );
|
||||
} elseif ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
|
||||
$size = filesize( $attachment[0] );
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PHPMailer attachment file name.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param array $attachment PHPMailer attachment.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_attachment_file_name( $attachment ) {
|
||||
|
||||
$filetype = str_replace( ';', '', trim( $attachment[4] ) );
|
||||
|
||||
return ! empty( $attachment[2] ) ? trim( $attachment[2] ) : 'file-' . wp_hash( microtime() ) . '.' . $filetype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform remote request with merged default params.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param string $url Request url.
|
||||
* @param array $params Request params.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function remote_request( $url, $params ) {
|
||||
|
||||
if ( ! isset( $params['method'] ) ) {
|
||||
$params['method'] = 'POST';
|
||||
}
|
||||
|
||||
$params = Options::array_merge_recursive( $this->get_default_params(), $params );
|
||||
|
||||
/**
|
||||
* Filters request params.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param array $params Request params.
|
||||
* @param MailerAbstract $mailer Mailer object.
|
||||
*/
|
||||
$params = apply_filters( 'wp_mail_smtp_providers_mailer_remote_request_params', $params, $this );
|
||||
|
||||
/**
|
||||
* Filters request url.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param string $url Request url.
|
||||
* @param MailerAbstract $mailer Mailer object.
|
||||
*/
|
||||
$url = apply_filters( 'wp_mail_smtp_providers_mailer_remote_request_url', $url, $this );
|
||||
|
||||
return wp_safe_remote_request( $url, $params );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Connection object.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @return ConnectionInterface
|
||||
*/
|
||||
public function get_connection() {
|
||||
|
||||
return $this->connection;
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\MailCatcher;
|
||||
use WPMailSMTP\MailCatcherV6;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Whether the mailer has all its settings correctly set up and saved.
|
||||
*
|
||||
* @since 1.4.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mailer_complete();
|
||||
|
||||
/**
|
||||
* 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 MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
*/
|
||||
public function process_phpmailer( $phpmailer );
|
||||
}
|
||||
@@ -1,468 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Mailgun;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\MailCatcherInterface;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* API endpoint used for sites from all regions.
|
||||
*
|
||||
* @since 1.4.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const API_BASE_US = 'https://api.mailgun.net/v3/';
|
||||
|
||||
/**
|
||||
* API endpoint used for sites from EU region.
|
||||
*
|
||||
* @since 1.4.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const API_BASE_EU = 'https://api.eu.mailgun.net/v3/';
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = '';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $phpmailer, $connection = null ) {
|
||||
|
||||
// Default value should be defined before the parent class contructor fires.
|
||||
$this->url = self::API_BASE_US;
|
||||
|
||||
// We want to prefill everything from MailCatcher class, which extends PHPMailer.
|
||||
parent::__construct( $phpmailer, $connection );
|
||||
|
||||
// We have a special API URL to query in case of EU region.
|
||||
if ( $this->connection_options->get( $this->mailer, 'region' ) === 'EU' ) {
|
||||
$this->url = self::API_BASE_EU;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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->connection_options->get( $this->mailer, 'domain' ) . '/messages' );
|
||||
|
||||
$this->set_header( 'Authorization', 'Basic ' . base64_encode( 'api:' . $this->connection_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 = 'html';
|
||||
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$type = 'text';
|
||||
}
|
||||
|
||||
if ( ! empty( $content ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
$type => $content,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are process for this mailer - they should be in body.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param array $headers
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
$this->set_body_header( $name, $value );
|
||||
}
|
||||
|
||||
// Add custom PHPMailer-specific header.
|
||||
$this->set_body_header( 'X-Mailer', 'WPMailSMTP/Mailer/' . $this->mailer . ' ' . WPMS_PLUGIN_VER );
|
||||
}
|
||||
|
||||
/**
|
||||
* This mailer supports email-related custom headers inside a body of the message with a special prefix "h:".
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function set_body_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'h:' . $name => WP::sanitize_value( $value ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* It's the last one, so we can modify the whole body.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $attachments The array of attachments data.
|
||||
*/
|
||||
public function set_attachments( $attachments ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh, Generic.Metrics.NestingLevel.MaxExceeded
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$payload = '';
|
||||
$data = [];
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = $this->get_attachment_file_content( $attachment );
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = [
|
||||
'content' => $file,
|
||||
'name' => $this->get_attachment_file_name( $attachment ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
|
||||
// First, generate a boundary for the multipart message.
|
||||
$boundary = $this->phpmailer->generate_id();
|
||||
|
||||
// Iterate through pre-built params and build a payload.
|
||||
foreach ( $this->body as $key => $value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $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->connection_options->get( 'mail', 'return_path' ) !== true ||
|
||||
! filter_var( $email, FILTER_VALIDATE_EMAIL )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'sender' => $email,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 2.5.0
|
||||
*
|
||||
* @param mixed $response Response data.
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
parent::process_response( $response );
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $this->response['body']->id ) ) {
|
||||
$this->phpmailer->MessageID = $this->response['body']->id;
|
||||
$this->verify_sent_status = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* In Mailgun's case it looks like we have to check if the response body has the message ID.
|
||||
* All successful API responses should have `id` key in the response body.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_email_sent() {
|
||||
|
||||
$is_sent = false;
|
||||
|
||||
if (
|
||||
wp_remote_retrieve_response_code( $this->response ) === $this->email_sent_code &&
|
||||
! empty( $this->response['body']->id )
|
||||
) {
|
||||
$is_sent = true;
|
||||
}
|
||||
|
||||
/** This filter is documented in src/Providers/MailerAbstract.php. */
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_is_email_sent', $is_sent, $this->mailer );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Mailgun-specific response with a helpful error.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_response_error() {
|
||||
|
||||
$error_text[] = $this->error_message;
|
||||
|
||||
if ( ! empty( $this->response ) ) {
|
||||
$body = wp_remote_retrieve_body( $this->response );
|
||||
|
||||
if ( ! empty( $body->message ) ) {
|
||||
$error_text[] = Helpers::format_error_message( $body->message );
|
||||
} else {
|
||||
$error_text[] = WP::wp_remote_get_response_error_message( $this->response );
|
||||
}
|
||||
}
|
||||
|
||||
return implode( WP::EOL, array_map( 'esc_textarea', array_filter( $error_text ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$mg_text = array();
|
||||
|
||||
$mailgun = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
$mg_text[] = '<strong>Api Key / Domain:</strong> ' . ( ! empty( $mailgun['api_key'] ) && ! empty( $mailgun['domain'] ) ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $mg_text );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
// API key is the only required option.
|
||||
if (
|
||||
! empty( $options['api_key'] ) &&
|
||||
! empty( $options['domain'] )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Mailgun;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Option.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailgun constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $connection = null ) {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/mailgun.svg',
|
||||
'slug' => 'mailgun',
|
||||
'title' => esc_html__( 'Mailgun', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses(
|
||||
/* translators: %1$s - URL to mailgun.com; %2$s - URL to Mailgun documentation on wpmailsmtp.com */
|
||||
__( '<a href="%1$s" target="_blank" rel="noopener noreferrer">Mailgun</a> is a transactional email provider that offers a generous 3-month free trial. After that, it offers a \'Pay As You Grow\' plan that allows you to pay for what you use without committing to a fixed monthly rate.<br><br>To get started, read our <a href="%2$s" target="_blank" rel="noopener noreferrer">Mailgun documentation</a>.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'https://www.mailgun.com',
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-mailgun-mailer-in-wp-mail-smtp/', 'Mailgun documentation' ) )
|
||||
),
|
||||
),
|
||||
$connection
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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( 'Mailgun API Key', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->connection_options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_MAILGUN_API_KEY' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
<p class="desc">
|
||||
<?php
|
||||
echo wp_kses(
|
||||
sprintf( /* translators: %s - API key URL. */
|
||||
__( 'Follow this link to <a href="%s" target="_blank" rel="noopener noreferrer">get a Mailgun API Key</a>. Generate a key in the "Mailgun API Keys" section.', 'wp-mail-smtp' ),
|
||||
'https://app.mailgun.com/settings/api_security'
|
||||
),
|
||||
[
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
);
|
||||
?>
|
||||
</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->connection_options->get( $this->get_slug(), 'domain' ) ); ?>"
|
||||
<?php echo $this->connection_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/sending/domains" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get a Domain Name', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Region -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-region" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-radio wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label><?php esc_html_e( 'Region', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region-us">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region-us"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][region]" value="US"
|
||||
<?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'region' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'US', $this->connection_options->get( $this->get_slug(), 'region' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'US', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region-eu">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region-eu"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][region]" value="EU"
|
||||
<?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'region' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'EU', $this->connection_options->get( $this->get_slug(), 'region' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'EU', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'Define which endpoint you want to use for sending messages.', 'wp-mail-smtp' ); ?><br>
|
||||
<?php esc_html_e( 'If you are operating under EU laws, you may be required to use EU region.', 'wp-mail-smtp' ); ?>
|
||||
<?php
|
||||
printf(
|
||||
wp_kses(
|
||||
/* translators: %s - URL to Mailgun.com page. */
|
||||
__( '<a href="%s" rel="" target="_blank">More information</a> on Mailgun.com.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'https://www.mailgun.com/regions'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -1,540 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Helpers\UI;
|
||||
use WPMailSMTP\Options;
|
||||
|
||||
/**
|
||||
* Abstract Class ProviderAbstract to contain common providers functionality.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class OptionsAbstract implements OptionsInterface {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $logo_url = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $slug = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $title = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $description = '';
|
||||
/**
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $notices = array();
|
||||
/**
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $recommended = false;
|
||||
/**
|
||||
* @since 1.7.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $disabled = false;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $php = WPMS_PHP_VER;
|
||||
/**
|
||||
* @var Options
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* An array with mailer supported setting fields.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $supports;
|
||||
|
||||
/**
|
||||
* The Connection object.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @var ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* The connection options object.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @var Options
|
||||
*/
|
||||
protected $connection_options;
|
||||
|
||||
/**
|
||||
* ProviderAbstract constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 2.3.0 Added supports parameter.
|
||||
*
|
||||
* @param array $params The mailer options parameters.
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $params, $connection = null ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
|
||||
|
||||
if ( ! is_null( $connection ) ) {
|
||||
$this->connection = $connection;
|
||||
} else {
|
||||
$this->connection = wp_mail_smtp()->get_connections_manager()->get_primary_connection();
|
||||
}
|
||||
|
||||
$this->connection_options = $this->connection->get_options();
|
||||
|
||||
if (
|
||||
empty( $params['slug'] ) ||
|
||||
empty( $params['title'] )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->slug = sanitize_key( $params['slug'] );
|
||||
$this->title = sanitize_text_field( $params['title'] );
|
||||
|
||||
if ( ! empty( $params['description'] ) ) {
|
||||
$this->description = wp_kses_post( $params['description'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $params['notices'] ) ) {
|
||||
foreach ( (array) $params['notices'] as $key => $notice ) {
|
||||
$key = sanitize_key( $key );
|
||||
if ( empty( $key ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$notice = wp_kses(
|
||||
$notice,
|
||||
array(
|
||||
'br' => true,
|
||||
'strong' => true,
|
||||
'em' => true,
|
||||
'a' => array(
|
||||
'href' => true,
|
||||
'rel' => true,
|
||||
'target' => true,
|
||||
),
|
||||
)
|
||||
);
|
||||
if ( empty( $notice ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->notices[ $key ] = $notice;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $params['recommended'] ) ) {
|
||||
$this->recommended = (bool) $params['recommended'];
|
||||
}
|
||||
if ( isset( $params['disabled'] ) ) {
|
||||
$this->disabled = (bool) $params['disabled'];
|
||||
}
|
||||
|
||||
if ( ! empty( $params['php'] ) ) {
|
||||
$this->php = sanitize_text_field( $params['php'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $params['logo_url'] ) ) {
|
||||
$this->logo_url = esc_url_raw( $params['logo_url'] );
|
||||
}
|
||||
|
||||
$this->supports = ( ! empty( $params['supports'] ) ) ? $params['supports'] : $this->get_supports_defaults();
|
||||
|
||||
$this->options = Options::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_logo_url() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_logo_url', $this->logo_url, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_slug() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_slug', $this->slug, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_title() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_title', $this->title, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_description() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_description', $this->description, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Some mailers may display a notice above its options.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_notice( $type ) {
|
||||
|
||||
$type = sanitize_key( $type );
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_notice', isset( $this->notices[ $type ] ) ? $this->notices[ $type ] : '', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_php_version() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_php_version', $this->php, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
?>
|
||||
|
||||
<!-- SMTP Host -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-host" 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() ); ?>-host"><?php esc_html_e( 'SMTP Host', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][host]" type="text"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'host' ) ); ?>"
|
||||
<?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'host' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-host" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Encryption -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-encryption" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-radio wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="none"
|
||||
<?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'none', $this->connection_options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'None', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="ssl"
|
||||
<?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'ssl', $this->connection_options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'SSL', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="tls"
|
||||
<?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'tls', $this->connection_options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'TLS', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'For most servers TLS is the recommended option. If your SMTP provider offers both SSL and TLS options, we recommend using TLS.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Port -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-number wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][port]" type="number"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'port' ) ); ?>"
|
||||
<?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'port' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="small-text" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PHPMailer SMTPAutoTLS -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-autotls" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear <?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'encryption' ) || 'tls' === $this->connection_options->get( $this->get_slug(), 'encryption' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"><?php esc_html_e( 'Auto TLS', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php
|
||||
UI::toggle(
|
||||
[
|
||||
'name' => 'wp-mail-smtp[' . $this->get_slug() . '][autotls]',
|
||||
'id' => 'wp-mail-smtp-setting-' . $this->get_slug() . '-autotls',
|
||||
'checked' => (bool) $this->connection_options->get( $this->get_slug(), 'autotls' ),
|
||||
'disabled' => $this->connection_options->is_const_defined( $this->get_slug(), 'autotls' ),
|
||||
]
|
||||
);
|
||||
?>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'By default, TLS encryption is automatically used if the server supports it (recommended). In some cases, due to server misconfigurations, this can cause issues and may need to be disabled.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Authentication -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-auth" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php
|
||||
UI::toggle(
|
||||
[
|
||||
'name' => 'wp-mail-smtp[' . $this->get_slug() . '][auth]',
|
||||
'id' => 'wp-mail-smtp-setting-' . $this->get_slug() . '-auth',
|
||||
'checked' => (bool) $this->connection_options->get( $this->get_slug(), 'auth' ),
|
||||
'disabled' => $this->connection_options->is_const_defined( $this->get_slug(), 'auth' ),
|
||||
]
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Username -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-user" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear <?php echo ! $this->connection_options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->connection_options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user"><?php esc_html_e( 'SMTP Username', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][user]" type="text"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'user' ) ); ?>"
|
||||
<?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'user' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user" spellcheck="false" autocomplete="new-password"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Password -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-pass" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-password wp-mail-smtp-clear <?php echo ! $this->connection_options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->connection_options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"><?php esc_html_e( 'SMTP Password', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->connection_options->is_const_defined( $this->get_slug(), 'pass' ) ) : ?>
|
||||
<input type="text" value="*************" disabled id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"/>
|
||||
|
||||
<?php $this->display_const_set_message( 'WPMS_SMTP_PASS' ); ?>
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - constant name: WPMS_SMTP_PASS. */
|
||||
esc_html__( 'To change the password you need to change the value of the constant there: %s', 'wp-mail-smtp' ),
|
||||
'<code>define( \'WPMS_SMTP_PASS\', \'your_old_password\' );</code>'
|
||||
);
|
||||
?>
|
||||
<br>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %1$s - wp-config.php file, %2$s - WPMS_ON constant name. */
|
||||
esc_html__( 'If you want to disable the use of constants, find in %1$s file the constant %2$s and turn if off:', 'wp-mail-smtp' ),
|
||||
'<code>wp-config.php</code>',
|
||||
'<code>WPMS_ON</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<pre>
|
||||
define( 'WPMS_ON', false );
|
||||
</pre>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'All the defined constants will stop working and you will be able to change all the values on this page.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][pass]" type="password"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'pass' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass" spellcheck="false" autocomplete="new-password"
|
||||
/>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'The password is encrypted in the database, but for improved security we recommend using your site\'s WordPress configuration file to set your password.', 'wp-mail-smtp' ); ?>
|
||||
<br>
|
||||
<?php
|
||||
printf(
|
||||
'<a href="%1$s" target="_blank" rel="noopener noreferrer"><strong>%2$s</strong></a>',
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-secure-smtp-settings-by-using-constants/', 'SMTP Password - Learn More' ) ),
|
||||
esc_html__( 'Learn More', 'wp-mail-smtp' )
|
||||
)
|
||||
?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this mailer is recommended or not.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_recommended() {
|
||||
|
||||
return (bool) apply_filters( 'wp_mail_smtp_providers_provider_is_recommended', $this->recommended, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this mailer is disabled or not.
|
||||
* Used for displaying Pro mailers inside Lite plugin.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_disabled() {
|
||||
|
||||
return (bool) apply_filters( 'wp_mail_smtp_providers_provider_is_disabled', $this->disabled, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we can use this provider based on the PHP version.
|
||||
* Valid for those, that use SDK.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_php_correct() {
|
||||
return version_compare( phpversion(), $this->php, '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a helpful message to those users, that are using an outdated version of PHP,
|
||||
* which is not supported by the currently selected Provider.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function display_php_warning() {
|
||||
?>
|
||||
|
||||
<blockquote>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %1$s - Provider name; %2$s - PHP version required by Provider; %3$s - current PHP version. */
|
||||
esc_html__( '%1$s requires PHP %2$s to work and does not support your current PHP version %3$s. Please contact your host and request a PHP upgrade to the latest one.', 'wp-mail-smtp' ),
|
||||
esc_html( $this->get_title() ),
|
||||
esc_html( $this->php ),
|
||||
esc_html( phpversion() )
|
||||
);
|
||||
?>
|
||||
<br>
|
||||
<?php esc_html_e( 'Meanwhile you can switch to some other mailers.', 'wp-mail-smtp' ); ?>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a helpful message to those users, that are using an outdated version of PHP,
|
||||
* which is not supported by the currently selected Provider.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected function display_ssl_warning() {
|
||||
?>
|
||||
|
||||
<blockquote>
|
||||
<?php
|
||||
printf(
|
||||
wp_kses( /* translators: %s - Provider name */
|
||||
__( '%s requires an SSL certificate, and so is not currently compatible with your site. Please contact your host to request a SSL certificate, or check out <a href="https://www.wpbeginner.com/wp-tutorials/how-to-add-ssl-and-https-in-wordpress/" target="_blank">WPBeginner\'s tutorial on how to set up SSL</a>.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
),
|
||||
esc_html( $this->get_title() )
|
||||
);
|
||||
?>
|
||||
<br>
|
||||
<br>
|
||||
<?php esc_html_e( 'If you\'d prefer not to set up SSL, or need an SMTP solution in the meantime, please select a different mailer option.', 'wp-mail-smtp' ); ?>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a message of a constant that was set inside wp-config.php file.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param string $constant Constant name.
|
||||
*/
|
||||
protected function display_const_set_message( $constant ) {
|
||||
|
||||
printf( '<p class="desc">%s</p>', $this->options->get_const_set_message( $constant ) ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the defaults for the mailer supported settings.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_supports_defaults() {
|
||||
|
||||
return [
|
||||
'from_email' => true,
|
||||
'from_name' => true,
|
||||
'return_path' => true,
|
||||
'from_email_force' => true,
|
||||
'from_name_force' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mailer supported settings.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_supports() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_supports', $this->supports, $this );
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
<?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();
|
||||
|
||||
/**
|
||||
* Get the mailer supported settings.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function get_supports();
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Outlook;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Outlook Options constructor.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/microsoft.svg',
|
||||
'slug' => 'outlook',
|
||||
'title' => esc_html__( '365 / Outlook', 'wp-mail-smtp' ),
|
||||
'disabled' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
?>
|
||||
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading">
|
||||
<p>
|
||||
<?php esc_html_e( 'We\'re sorry, the Microsoft Outlook mailer is not available on your plan. Please upgrade to the PRO plan to unlock all these awesome features.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?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 {
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->options->get_group( $this->mailer );
|
||||
|
||||
// Host and Port are the only really required options.
|
||||
if (
|
||||
! empty( $options['host'] ) &&
|
||||
! empty( $options['port'] )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?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()->assets_url . '/images/providers/pepipost-smtp.png',
|
||||
'slug' => 'pepipost',
|
||||
'title' => esc_html__( 'Pepipost SMTP', 'wp-mail-smtp' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,477 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\PepipostAPI;
|
||||
|
||||
use WPMailSMTP\MailCatcherInterface;
|
||||
use WPMailSMTP\Options as PluginOptions;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Pepipost API mailer.
|
||||
*
|
||||
* @since 1.8.0 Pepipost - SendGrid migration API.
|
||||
* @since 2.2.0 Rewrote this class to use native Pepipost API.
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 202;
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 1.8.0
|
||||
* @since 2.2.0 Changed the API url to Pepipost API v5.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://api.pepipost.com/v5/mail/send';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 1.8.0
|
||||
* @since 2.2.0 Changed the API key header (API v5 changes).
|
||||
*
|
||||
* @param MailCatcherInterface $phpmailer The MailCatcher instance.
|
||||
*/
|
||||
public function __construct( $phpmailer ) {
|
||||
|
||||
// We want to prefill everything from MailCatcher class, which extends PHPMailer.
|
||||
parent::__construct( $phpmailer );
|
||||
|
||||
$this->set_header( 'api_key', $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.
|
||||
* Pepipost requires a JSON, so we encode the body.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
$body = parent::get_body();
|
||||
|
||||
return wp_json_encode( $body );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the FROM header of the email.
|
||||
*
|
||||
* @since 1.8.0
|
||||
* @since 2.2.0 Changed the attribute names (API v5 changes).
|
||||
*
|
||||
* @param string $email From mail.
|
||||
* @param string $name From name.
|
||||
*/
|
||||
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(
|
||||
[
|
||||
'from' => $from,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the names/emails of people who will receive the email.
|
||||
*
|
||||
* @since 1.8.0
|
||||
* @since 2.2.0 change the attribute names (API v5 changes).
|
||||
*
|
||||
* @param array $recipients List of recipients: cc/bcc/to.
|
||||
*/
|
||||
public function set_recipients( $recipients ) {
|
||||
|
||||
if ( empty( $recipients ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
if ( ! empty( $recipients['to'] ) ) {
|
||||
$data['to'] = $this->prepare_list_of_to_emails( $recipients['to'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $recipients['cc'] ) ) {
|
||||
$data['cc'] = $this->prepare_list_of_emails( $recipients['cc'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $recipients['bcc'] ) ) {
|
||||
$data['bcc'] = $this->prepare_list_of_emails( $recipients['bcc'] );
|
||||
}
|
||||
|
||||
$this->set_body_personalizations( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the email content.
|
||||
* Pepipost API only supports HTML emails, so we have to replace new lines in plain text emails with <br>.
|
||||
*
|
||||
* @since 1.8.0
|
||||
* @since 2.2.0 Change the way the content is prepared (API v5 changes).
|
||||
*
|
||||
* @param array|string $content Email content.
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$html = '';
|
||||
|
||||
if ( ! is_array( $content ) ) {
|
||||
$html = $content;
|
||||
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$html = nl2br( $html );
|
||||
}
|
||||
} else {
|
||||
|
||||
if ( ! empty( $content['html'] ) ) {
|
||||
$html = $content['html'];
|
||||
} elseif ( ! empty( $content['text'] ) ) {
|
||||
$html = nl2br( $content['text'] );
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
[
|
||||
'content' => [
|
||||
[
|
||||
'type' => 'html',
|
||||
'value' => $html,
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are processed for this mailer - they should be in body (personalizations).
|
||||
*
|
||||
* @since 1.8.0
|
||||
* @since 2.2.0 Change the way the headers are processed (API v5 changes).
|
||||
*
|
||||
* @param array $headers The email headers to be applied.
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
$valid_headers = [];
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
$valid_headers[ $name ] = WP::sanitize_value( $value );
|
||||
}
|
||||
|
||||
// Add custom PHPMailer-specific header.
|
||||
$valid_headers['X-Mailer'] = WP::sanitize_value( 'WPMailSMTP/Mailer/' . $this->mailer . ' ' . WPMS_PLUGIN_VER );
|
||||
|
||||
if ( ! empty( $valid_headers ) ) {
|
||||
$this->set_body_personalizations( [ 'headers' => $valid_headers ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pepipost API 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 will be reported by the API response.
|
||||
*
|
||||
* @since 1.8.0
|
||||
* @since 2.2.0 Change the way the attachments are processed (API v5 changes).
|
||||
*
|
||||
* @param array $attachments The list of attachments data.
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $this->prepare_attachments( $attachments );
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'attachments' => $data,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the attachments data for Pepipost API.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
* @param array $attachments Array of attachments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepare_attachments( $attachments ) {
|
||||
|
||||
$data = [];
|
||||
|
||||
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[] = [
|
||||
'content' => base64_encode( $file ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
||||
'name' => $attachment[2],
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the reply-to property of the email.
|
||||
* Pepipost API only supports one reply_to email, so we take the first one and discard the rest.
|
||||
*
|
||||
* @since 1.8.0
|
||||
* @since 2.2.0 Change the way the reply_to is processed (API v5 changes).
|
||||
*
|
||||
* @param array $reply_to Name/email for reply-to feature.
|
||||
*/
|
||||
public function set_reply_to( $reply_to ) {
|
||||
|
||||
if ( empty( $reply_to ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$email_array = array_shift( $reply_to );
|
||||
|
||||
if ( empty( $email_array[0] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$email = $email_array[0];
|
||||
|
||||
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $email ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'reply_to' => $email,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pepipost API doesn't support sender or return_path params.
|
||||
* So we do nothing.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @param string $from_email The from email address.
|
||||
*/
|
||||
public function set_return_path( $from_email ) {}
|
||||
|
||||
/**
|
||||
* Get a Pepipost-specific response with a helpful error.
|
||||
*
|
||||
* @see https://developers.pepipost.com/email-api/email-api/sendemail#responses
|
||||
*
|
||||
* @since 1.8.0
|
||||
* @since 2.2.0 Change the way the response error message is processed (API v5 changes).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_response_error() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
|
||||
|
||||
$body = (array) wp_remote_retrieve_body( $this->response );
|
||||
|
||||
$error = ! empty( $body['error'] ) ? $body['error'] : '';
|
||||
$info = ! empty( $body['info'] ) ? $body['info'] : '';
|
||||
$message = '';
|
||||
|
||||
if ( ! empty( $this->error_message ) ) {
|
||||
$message = $this->error_message;
|
||||
} elseif ( is_string( $error ) ) {
|
||||
$message = $error . ( ( ! empty( $info ) ) ? ' - ' . $info : '' );
|
||||
} elseif ( is_array( $error ) ) {
|
||||
$message = '';
|
||||
|
||||
foreach ( $error as $item ) {
|
||||
$message .= sprintf(
|
||||
'%1$s (%2$s - %3$s)',
|
||||
! empty( $item->description ) ? $item->description : esc_html__( 'General error', 'wp-mail-smtp' ),
|
||||
! empty( $item->message ) ? $item->message : esc_html__( 'Error', 'wp-mail-smtp' ),
|
||||
! empty( $item->field ) ? $item->field : ''
|
||||
) . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mailer debug information, that is helpful during support.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$sendgrid_text[] = '<strong>Api Key:</strong> ' . ( $this->is_mailer_complete() ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $sendgrid_text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the mailer has all its settings correctly set up and saved.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->options->get_group( $this->mailer );
|
||||
|
||||
// API key is the only required option.
|
||||
if ( ! empty( $options['api_key'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A special set method for Pepipost API "personalizations" attribute.
|
||||
* We are sending one email at a time, so we should set just the first
|
||||
* personalization item.
|
||||
*
|
||||
* Mainly used in set_headers and set_recipients.
|
||||
*
|
||||
* @see https://developers.pepipost.com/email-api/email-api/sendemail
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
* @param array $data The personalizations array of data (array of arrays).
|
||||
*/
|
||||
private function set_body_personalizations( $data ) {
|
||||
|
||||
if ( empty( $data ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $this->body['personalizations'][0] ) ) {
|
||||
$this->body['personalizations'][0] = PluginOptions::array_merge_recursive(
|
||||
$this->body['personalizations'][0],
|
||||
$data
|
||||
);
|
||||
} else {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'personalizations' => [
|
||||
$data,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare list of emails by filtering valid emails first.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
* @param array $items A 2D array of email and name pair items (0 = email, 1 = name).
|
||||
*
|
||||
* @return array 2D array with 'email' keys.
|
||||
*/
|
||||
private function prepare_list_of_emails( $items ) {
|
||||
|
||||
$valid_emails = array_filter(
|
||||
array_column( $items, 0 ),
|
||||
function ( $email ) {
|
||||
return filter_var( $email, FILTER_VALIDATE_EMAIL );
|
||||
}
|
||||
);
|
||||
|
||||
return array_map(
|
||||
function( $email ) {
|
||||
return [ 'email' => $email ];
|
||||
},
|
||||
$valid_emails
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare list of TO emails by filtering valid emails first
|
||||
* and returning array of arrays (email, name).
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
* @param array $items A 2D array of email and name pair items (0 = email, 1 = name).
|
||||
*
|
||||
* @return array 2D array with 'email' and optional 'name' attributes.
|
||||
*/
|
||||
private function prepare_list_of_to_emails( $items ) {
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $items as $item ) {
|
||||
$email = filter_var( $item[0], FILTER_VALIDATE_EMAIL );
|
||||
|
||||
if ( empty( $email ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pair['email'] = $email;
|
||||
|
||||
if ( ! empty( $item[1] ) ) {
|
||||
$pair['name'] = $item[1];
|
||||
}
|
||||
|
||||
$data[] = $pair;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\PepipostAPI;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
use WPMailSMTP\Options as PluginOptions;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
const SLUG = 'pepipostapi';
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @since 1.8.0
|
||||
* @since 2.3.0 Added 'supports' parameter.
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$description = sprintf(
|
||||
wp_kses( /* translators: %1$s - URL to pepipost.com site. */
|
||||
__( '<a href="%1$s" target="_blank" rel="noopener noreferrer">Pepipost</a> is a transactional email service. Every month Pepipost delivers over 8 billion emails from 20,000+ customers. Their mission is to reliably send emails in the most efficient way and at the most disruptive pricing ever. Pepipost provides users 30,000 free emails the first 30 days.', 'wp-mail-smtp' ) .
|
||||
'<br><br>' .
|
||||
/* translators: %1$s - URL to wpmailsmtp.com doc. */
|
||||
__( 'Read our <a href="%2$s" target="_blank" rel="noopener noreferrer">Pepipost documentation</a> to learn how to configure Pepipost and improve your email deliverability.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => true,
|
||||
'a' => array(
|
||||
'href' => true,
|
||||
'rel' => true,
|
||||
'target' => true,
|
||||
),
|
||||
)
|
||||
),
|
||||
'https://wpmailsmtp.com/go/pepipost/',
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-pepipost-mailer-in-wp-mail-smtp/', 'Pepipost documentation' ) )
|
||||
);
|
||||
|
||||
$api_key = PluginOptions::init()->get( self::SLUG, 'api_key' );
|
||||
|
||||
if ( empty( $api_key ) ) {
|
||||
$description .= sprintf(
|
||||
'</p><p class="buttonned"><a href="%1$s" target="_blank" rel="noopener noreferrer" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-blueish">%2$s</a></p>',
|
||||
'https://wpmailsmtp.com/go/pepipost/',
|
||||
esc_html__( 'Get Started with Pepipost', 'wp-mail-smtp' )
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct(
|
||||
[
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/pepipost.png',
|
||||
'slug' => self::SLUG,
|
||||
'title' => esc_html__( 'Pepipost', 'wp-mail-smtp' ),
|
||||
'description' => $description,
|
||||
'php' => '5.3',
|
||||
'supports' => [
|
||||
'from_email' => true,
|
||||
'from_name' => true,
|
||||
'return_path' => false,
|
||||
'from_email_force' => true,
|
||||
'from_name_force' => true,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the mailer provider options.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
// Do not display options if PHP version is not correct.
|
||||
if ( ! $this->is_php_correct() ) {
|
||||
$this->display_php_warning();
|
||||
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- API Key -->
|
||||
<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() ); ?>-api_key"><?php esc_html_e( 'API Key', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->connection_options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_PEPIPOST_API_KEY' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %s - link to get an API Key. */
|
||||
esc_html__( 'Follow this link to get an API Key: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://app.pepipost.com/app/settings/integration" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get the API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -1,469 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Postmark;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\WP;
|
||||
use WPMailSMTP\MailCatcherInterface;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://api.postmarkapp.com/email';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $phpmailer, $connection = null ) {
|
||||
|
||||
// We want to prefill everything from MailCatcher class, which extends PHPMailer.
|
||||
parent::__construct( $phpmailer, $connection );
|
||||
|
||||
// Set mailer specific headers.
|
||||
$this->set_header( 'X-Postmark-Server-Token', $this->connection_options->get( $this->mailer, 'server_api_token' ) );
|
||||
$this->set_header( 'Accept', 'application/json' );
|
||||
$this->set_header( 'Content-Type', 'application/json' );
|
||||
|
||||
// Set mailer specific body parameters.
|
||||
$message_stream = $this->get_message_stream();
|
||||
|
||||
if ( ! empty( $message_stream ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'MessageStream' => $message_stream,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are processed for this mailer - they should be in body.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array $headers Headers array.
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
$this->set_body_header( $name, $value );
|
||||
}
|
||||
|
||||
// Add custom PHPMailer-specific header.
|
||||
$this->set_body_header( 'X-Mailer', 'WPMailSMTP/Mailer/' . $this->mailer . ' ' . WPMS_PLUGIN_VER );
|
||||
$this->set_body_header( 'Message-ID', $this->phpmailer->getLastMessageID() );
|
||||
}
|
||||
|
||||
/**
|
||||
* This mailer supports email-related custom headers inside a body of the message.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param string $name Header name.
|
||||
* @param string $value Header value.
|
||||
*/
|
||||
public function set_body_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$headers = isset( $this->body['Headers'] ) ? (array) $this->body['Headers'] : [];
|
||||
|
||||
if ( $name !== 'Message-ID' ) {
|
||||
$value = WP::sanitize_value( $value );
|
||||
}
|
||||
|
||||
// Prevent duplicates.
|
||||
$key = array_search( $name, array_column( $headers, 'Name' ), true );
|
||||
|
||||
if ( $key !== false ) {
|
||||
unset( $headers[ $key ] );
|
||||
}
|
||||
|
||||
$headers[] = [
|
||||
'Name' => $name,
|
||||
'Value' => $value,
|
||||
];
|
||||
|
||||
$this->body['Headers'] = array_values( $headers );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the From information for an email.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param string $email The sender email address.
|
||||
* @param string $name The sender name.
|
||||
*/
|
||||
public function set_from( $email, $name ) {
|
||||
|
||||
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
[
|
||||
'From' => $this->phpmailer->addrFormat( [ $email, $name ] ),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email recipients: to, cc, bcc.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array $recipients Email recipients.
|
||||
*/
|
||||
public function set_recipients( $recipients ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
|
||||
if ( empty( $recipients ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$default = [ 'to', 'cc', 'bcc' ];
|
||||
|
||||
foreach ( $recipients as $type => $emails ) {
|
||||
if (
|
||||
! in_array( $type, $default, true ) ||
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $emails as $email ) {
|
||||
$addr = isset( $email[0] ) ? $email[0] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = $this->phpmailer->addrFormat( $email );
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
ucfirst( $type ) => implode( ',', $data ),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Reply To information for an email.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array $emails Reply To email addresses.
|
||||
*/
|
||||
public function set_reply_to( $emails ) {
|
||||
|
||||
if ( empty( $emails ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $emails as $email ) {
|
||||
$addr = isset( $email[0] ) ? $email[0] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = $this->phpmailer->addrFormat( $email );
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'ReplyTo' => implode( ',', $data ),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email subject.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param string $subject Email subject.
|
||||
*/
|
||||
public function set_subject( $subject ) {
|
||||
|
||||
$this->set_body_param(
|
||||
[
|
||||
'Subject' => $subject,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email content.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param string|array $content Email content.
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_array( $content ) ) {
|
||||
if ( ! empty( $content['text'] ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'TextBody' => $content['text'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $content['html'] ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'HtmlBody' => $content['html'],
|
||||
]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'TextBody' => $content,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'HtmlBody' => $content,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attachments for an email.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array $attachments Attachments array.
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $this->prepare_attachments( $attachments );
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'Attachments' => $data,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare attachments data for Postmark API.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array $attachments Array of attachments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepare_attachments( $attachments ) {
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = $this->get_attachment_file_content( $attachment );
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = [
|
||||
'Name' => $this->get_attachment_file_name( $attachment ),
|
||||
'Content' => base64_encode( $file ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
||||
'ContentType' => $attachment[4],
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't support this.
|
||||
* Return path can be configured in Postmark account.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param string $email Return Path email address.
|
||||
*/
|
||||
public function set_return_path( $email ) { }
|
||||
|
||||
/**
|
||||
* Redefine the way email body is returned.
|
||||
* By default, we are sending an array of data.
|
||||
* Postmark requires a JSON, so we encode the body.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
$body = parent::get_body();
|
||||
|
||||
return wp_json_encode( $body );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 3.1.0
|
||||
*
|
||||
* @param mixed $response Response data.
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
parent::process_response( $response );
|
||||
|
||||
if (
|
||||
! is_wp_error( $response ) &&
|
||||
! empty( $this->response['body']->MessageID )
|
||||
) {
|
||||
$this->phpmailer->addCustomHeader( 'X-Msg-ID', $this->response['body']->MessageID );
|
||||
$this->verify_sent_status = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Postmark-specific response with a helpful error.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_response_error() {
|
||||
|
||||
$error_text[] = $this->error_message;
|
||||
|
||||
if ( ! empty( $this->response ) ) {
|
||||
$body = wp_remote_retrieve_body( $this->response );
|
||||
|
||||
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||
if ( ! empty( $body->Message ) ) {
|
||||
$message = $body->Message;
|
||||
$code = ! empty( $body->ErrorCode ) ? $body->ErrorCode : '';
|
||||
|
||||
$error_text[] = Helpers::format_error_message( $message, $code );
|
||||
} else {
|
||||
$error_text[] = WP::wp_remote_get_response_error_message( $this->response );
|
||||
}
|
||||
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||
}
|
||||
|
||||
return implode( WP::EOL, array_map( 'esc_textarea', array_filter( $error_text ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mailer debug information, that is helpful during support.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$options = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
$text[] = '<strong>' . esc_html__( 'Server API Token:', 'wp-mail-smtp' ) . '</strong> ' .
|
||||
( ! empty( $options['server_api_token'] ) ? 'Yes' : 'No' );
|
||||
$text[] = '<strong>' . esc_html__( 'Message Stream ID:', 'wp-mail-smtp' ) . '</strong> ' .
|
||||
( ! empty( $this->get_message_stream() ) ? esc_html( $this->get_message_stream() ) : 'No' );
|
||||
|
||||
return implode( '<br>', $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Message Stream ID.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @link https://postmarkapp.com/message-streams
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_message_stream() {
|
||||
|
||||
$message_stream = $this->connection_options->get( $this->mailer, 'message_stream' );
|
||||
|
||||
/**
|
||||
* Filters Message Stream ID.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @link https://postmarkapp.com/message-streams
|
||||
*
|
||||
* @param string $message_stream Message Stream ID.
|
||||
*/
|
||||
return apply_filters( 'wp_mail_smtp_providers_postmark_mailer_get_message_stream', $message_stream );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the mailer has all its settings correctly set up and saved.
|
||||
*
|
||||
* This mailer is configured when `server_api_token` setting is defined.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
if ( ! empty( $options['server_api_token'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Postmark;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*/
|
||||
const SLUG = 'postmark';
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $connection = null ) {
|
||||
|
||||
$description = sprintf(
|
||||
wp_kses( /* translators: %1$s - URL to postmarkapp.com site. */
|
||||
__( '<a href="%1$s" target="_blank" rel="noopener noreferrer">Postmark</a> is a transactional email provider that offers great deliverability and accessible pricing for any business. You can start out with the free trial that allows you to send 100 test emails each month via its secure API.', 'wp-mail-smtp' ) .
|
||||
'<br><br>' .
|
||||
/* translators: %2$s - URL to wpmailsmtp.com doc. */
|
||||
__( 'To get started, read our <a href="%2$s" target="_blank" rel="noopener noreferrer">Postmark documentation</a>.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'strong' => true,
|
||||
'br' => true,
|
||||
'a' => [
|
||||
'href' => true,
|
||||
'rel' => true,
|
||||
'target' => true,
|
||||
],
|
||||
]
|
||||
),
|
||||
'https://postmarkapp.com',
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-postmark-mailer-in-wp-mail-smtp/', 'Postmark documentation' ) )
|
||||
);
|
||||
|
||||
parent::__construct(
|
||||
[
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/postmark.svg',
|
||||
'slug' => self::SLUG,
|
||||
'title' => esc_html__( 'Postmark', 'wp-mail-smtp' ),
|
||||
'php' => '5.6',
|
||||
'description' => $description,
|
||||
'supports' => [
|
||||
'from_email' => true,
|
||||
'from_name' => true,
|
||||
'return_path' => false,
|
||||
'from_email_force' => true,
|
||||
'from_name_force' => true,
|
||||
],
|
||||
'recommended' => false,
|
||||
],
|
||||
$connection
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the mailer provider options.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
// Do not display options if PHP version is not correct.
|
||||
if ( ! $this->is_php_correct() ) {
|
||||
$this->display_php_warning();
|
||||
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- Server API Token -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-server_api_token" 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() ); ?>-server_api_token"><?php esc_html_e( 'Server API Token', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->connection_options->is_const_defined( $this->get_slug(), 'server_api_token' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-server_api_token"/>
|
||||
<?php $this->display_const_set_message( 'WPMS_POSTMARK_SERVER_API_TOKEN' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][server_api_token]"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'server_api_token' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-server_api_token"/>
|
||||
<?php endif; ?>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %s - Server API Token link. */
|
||||
esc_html__( 'Follow this link to get a Server API Token from Postmark: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://account.postmarkapp.com/api_tokens" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get Server API Token', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Message Stream ID -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-message_stream" 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() ); ?>-message_stream"><?php esc_html_e( 'Message Stream 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() ); ?>][message_stream]" type="text"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'message_stream' ) ); ?>"
|
||||
<?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'message_stream' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-message_stream" spellcheck="false"/>
|
||||
<?php
|
||||
if ( $this->connection_options->is_const_defined( $this->get_slug(), 'message_stream' ) ) {
|
||||
$this->display_const_set_message( 'WPMS_POSTMARK_MESSAGE_STREAM' );
|
||||
}
|
||||
?>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
wp_kses(
|
||||
/* translators: %s - URL to Postmark documentation on wpmailsmtp.com */
|
||||
__( 'Message Stream ID is <strong>optional</strong>. By default <strong>outbound</strong> (Default Transactional Stream) will be used. More information can be found in our <a href="%s" target="_blank" rel="noopener noreferrer">Postmark documentation</a>.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'strong' => [],
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
),
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-postmark-mailer-in-wp-mail-smtp/#message-stream', 'Postmark documentation - message stream' ) )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?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 {
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
// Host and Port are the only really required options.
|
||||
if (
|
||||
! empty( $options['host'] ) &&
|
||||
! empty( $options['port'] )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SMTP;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class SMTP.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* SMTP constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $connection = null ) {
|
||||
|
||||
parent::__construct(
|
||||
[
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/smtp.svg',
|
||||
'slug' => 'smtp',
|
||||
'title' => esc_html__( 'Other SMTP', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses(
|
||||
/* translators: %s - URL to SMTP documentation. */
|
||||
__( 'The Other SMTP option lets you send emails through an SMTP server instead of using a provider\'s API. This is easy and convenient, but it\'s less secure than the other mailers. Please note that your provider may not allow you to send a large number of emails. In that case, please use a different mailer.<br><br>To get started, read our <a href="%s" target="_blank" rel="noopener noreferrer">Other SMTP documentation</a>.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'br' => [],
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
),
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-other-smtp-mailer-in-wp-mail-smtp/', 'Other SMTP documentation' ) )
|
||||
),
|
||||
],
|
||||
$connection
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,478 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SMTPcom;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\MailCatcherInterface;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class Mailer for SMTP.com integration.
|
||||
*
|
||||
* @see https://www.smtp.com/smtp-api-documentation/ for the API documentation.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://api.smtp.com/v4/messages';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $phpmailer, $connection = null ) {
|
||||
|
||||
// We want to prefill everything from MailCatcher class, which extends PHPMailer.
|
||||
parent::__construct( $phpmailer, $connection );
|
||||
|
||||
// Set mailer specific headers.
|
||||
$this->set_header( 'Authorization', 'Bearer ' . $this->connection_options->get( $this->mailer, 'api_key' ) );
|
||||
$this->set_header( 'Accept', 'application/json' );
|
||||
$this->set_header( 'content-type', 'application/json' );
|
||||
|
||||
// Set mailer specific body parameters.
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'channel' => $this->connection_options->get( $this->mailer, 'channel' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way email body is returned.
|
||||
* By default we are sending an array of data.
|
||||
* SMTP.com requires a JSON, so we encode the body.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
$body = parent::get_body();
|
||||
|
||||
return wp_json_encode( $body );
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the FROM (name and email).
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $email From Email address.
|
||||
* @param string $name From Name.
|
||||
*/
|
||||
public function set_from( $email, $name = '' ) {
|
||||
|
||||
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$from['address'] = $email;
|
||||
|
||||
if ( ! empty( $name ) ) {
|
||||
$from['name'] = $name;
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'originator' => array(
|
||||
'from' => $from,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the CC/BCC/TO (with names and emails).
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $recipients
|
||||
*/
|
||||
public function set_recipients( $recipients ) {
|
||||
|
||||
if ( empty( $recipients ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Allow only these recipient types.
|
||||
$allowed_types = array( 'to', 'cc', 'bcc' );
|
||||
$data = array();
|
||||
|
||||
foreach ( $recipients as $type => $emails ) {
|
||||
if (
|
||||
! in_array( $type, $allowed_types, 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();
|
||||
$address = isset( $email[0] ) ? $email[0] : false;
|
||||
$name = isset( $email[1] ) ? $email[1] : false;
|
||||
|
||||
if ( ! filter_var( $address, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$holder['address'] = $address;
|
||||
if ( ! empty( $name ) ) {
|
||||
$holder['name'] = $name;
|
||||
}
|
||||
|
||||
array_push( $data[ $type ], $holder );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'recipients' => $data,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the email content.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array|string $content String when text/plain, array otherwise.
|
||||
*/
|
||||
public function set_content( $content ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$parts = [];
|
||||
|
||||
if ( is_array( $content ) ) {
|
||||
$allowed = [ 'text', 'html' ];
|
||||
|
||||
foreach ( $content as $type => $body ) {
|
||||
if (
|
||||
! in_array( $type, $allowed, true ) ||
|
||||
empty( $body )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content_type = 'text/plain';
|
||||
$content_value = $body;
|
||||
|
||||
if ( $type === 'html' ) {
|
||||
$content_type = 'text/html';
|
||||
}
|
||||
|
||||
$parts[] = [
|
||||
'type' => $content_type,
|
||||
'content' => $content_value,
|
||||
'charset' => $this->phpmailer->CharSet,
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$content_type = 'text/html';
|
||||
$content_value = $content;
|
||||
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$content_type = 'text/plain';
|
||||
}
|
||||
|
||||
$parts[] = [
|
||||
'type' => $content_type,
|
||||
'content' => $content_value,
|
||||
'charset' => $this->phpmailer->CharSet,
|
||||
];
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
[
|
||||
'body' => [
|
||||
'parts' => $parts,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are processed for this mailer - they should be in body.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $headers
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
$this->set_body_header( $name, $value );
|
||||
}
|
||||
|
||||
// Add custom PHPMailer-specific header.
|
||||
$this->set_body_header( 'X-Mailer', 'WPMailSMTP/Mailer/' . $this->mailer . ' ' . WPMS_PLUGIN_VER );
|
||||
}
|
||||
|
||||
/**
|
||||
* This mailer supports email-related custom headers inside a body of the message.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function set_body_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
if ( empty( $name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$headers = isset( $this->body['custom_headers'] ) ? (array) $this->body['custom_headers'] : array();
|
||||
|
||||
$headers[ $name ] = WP::sanitize_value( $value );
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'custom_headers' => $headers,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SMTP.com accepts an array of attachments in body.attachments section of the JSON payload.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $attachments The array of attachments data.
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = $this->get_attachment_file_content( $attachment );
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filetype = str_replace( ';', '', trim( $attachment[4] ) );
|
||||
|
||||
$data[] = [
|
||||
'content' => chunk_split( base64_encode( $file ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
||||
'type' => $filetype,
|
||||
'encoding' => 'base64',
|
||||
'filename' => $this->get_attachment_file_name( $attachment ),
|
||||
'disposition' => in_array( $attachment[6], [ 'inline', 'attachment' ], true ) ? $attachment[6] : 'attachment', // either inline or attachment.
|
||||
'cid' => empty( $attachment[7] ) ? '' : trim( (string) $attachment[7] ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'body' => [
|
||||
'attachments' => $data,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Reply-To part of the message.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $reply_to
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
$address = isset( $emails[0] ) ? $emails[0] : false;
|
||||
$name = isset( $emails[1] ) ? $emails[1] : false;
|
||||
|
||||
if ( ! filter_var( $address, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data['address'] = $address;
|
||||
if ( ! empty( $name ) ) {
|
||||
$data['name'] = $name;
|
||||
}
|
||||
|
||||
// Let the first valid email from the passed $reply_to serve as the reply_to parameter in STMP.com API.
|
||||
// Only one email address and name is allowed in the `reply_to` parameter in the SMTP.com API payload.
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'originator' => array(
|
||||
'reply_to' => $data,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SMTP.com doesn't support return_path params.
|
||||
* So we do nothing.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $from_email
|
||||
*/
|
||||
public function set_return_path( $from_email ) {}
|
||||
|
||||
/**
|
||||
* 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 2.5.0
|
||||
*
|
||||
* @param mixed $response Response data.
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
parent::process_response( $response );
|
||||
|
||||
if (
|
||||
! is_wp_error( $response ) &&
|
||||
! empty( $this->response['body']->data->message )
|
||||
) {
|
||||
preg_match( '/msg_id: (.*)/', $this->response['body']->data->message, $output );
|
||||
|
||||
if ( ! empty( $output[1] ) ) {
|
||||
$this->phpmailer->addCustomHeader( 'X-Msg-ID', $output[1] );
|
||||
$this->verify_sent_status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a SMTP.com-specific response with a helpful error.
|
||||
*
|
||||
* SMTP.com API error response (non 200 error code responses) is:
|
||||
* {
|
||||
* "status": "fail",
|
||||
* "data": {
|
||||
* "error_key": "short error message",
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* It's good to combine the error_key and the message together for the best error explanation.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_response_error() {
|
||||
|
||||
$error_text[] = $this->error_message;
|
||||
|
||||
if ( ! empty( $this->response ) ) {
|
||||
$body = wp_remote_retrieve_body( $this->response );
|
||||
|
||||
if ( ! empty( $body->data ) ) {
|
||||
foreach ( (array) $body->data as $error_key => $error_message ) {
|
||||
$error_text[] = Helpers::format_error_message( $error_message, $error_key );
|
||||
}
|
||||
} else {
|
||||
$error_text[] = WP::wp_remote_get_response_error_message( $this->response );
|
||||
}
|
||||
}
|
||||
|
||||
return implode( WP::EOL, array_map( 'esc_textarea', array_filter( $error_text ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mailer debug information, that is helpful during support.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$options = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
$text[] = '<strong>' . esc_html__( 'Api Key:', 'wp-mail-smtp' ) . '</strong> ' .
|
||||
( ! empty( $options['api_key'] ) ? 'Yes' : 'No' );
|
||||
$text[] = '<strong>' . esc_html__( 'Channel:', 'wp-mail-smtp' ) . '</strong> ' .
|
||||
( ! empty( $options['channel'] ) ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the mailer has all its settings correctly set up and saved.
|
||||
*
|
||||
* This mailer is configured when `api_key` and `channel` settings are defined.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
if ( ! empty( $options['api_key'] ) && ! empty( $options['channel'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SMTPcom;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
const SLUG = 'smtpcom';
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @since 2.3.0 Added supports parameter.
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $connection = null ) {
|
||||
|
||||
if ( is_null( $connection ) ) {
|
||||
$connection = wp_mail_smtp()->get_connections_manager()->get_primary_connection();
|
||||
}
|
||||
|
||||
$allowed_kses_html = array(
|
||||
'strong' => array(),
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
$description = sprintf(
|
||||
wp_kses( /* translators: %s - URL to smtp.com site. */
|
||||
__( '<strong><a href="%s" target="_blank" rel="noopener noreferrer">SMTP.com</a> is one of our recommended mailers.</strong> It\'s a transactional email provider that\'s currently used by 100,000+ businesses. SMTP.com is an established brand that\'s been offering email services for more than 20 years.<br><br>SMTP.com offers a free 30-day trial that allows you to send up to 50,000 emails.', 'wp-mail-smtp' ),
|
||||
$allowed_kses_html
|
||||
),
|
||||
'https://wpmailsmtp.com/go/smtp/'
|
||||
);
|
||||
$description .= '<br><br>';
|
||||
$description .= sprintf(
|
||||
wp_kses( /* translators: %s - URL to wpmailsmtp.com doc page for stmp.com. */
|
||||
__( 'To get started, read our <a href="%s" target="_blank" rel="noopener noreferrer">SMTP.com documentation</a>.', 'wp-mail-smtp' ),
|
||||
$allowed_kses_html
|
||||
),
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-smtp-com-mailer-in-wp-mail-smtp/', 'SMTP.com documentation' ) )
|
||||
);
|
||||
|
||||
$mailer_options = $connection->get_options()->get_group( self::SLUG );
|
||||
|
||||
if ( empty( $mailer_options['api_key'] ) && empty( $mailer_options['channel'] ) ) {
|
||||
$description .= sprintf(
|
||||
'</p><p class="buttonned"><a href="%1$s" target="_blank" rel="noopener noreferrer" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-blueish">%2$s</a></p>',
|
||||
'https://wpmailsmtp.com/go/smtp/',
|
||||
esc_html__( 'Get Started with SMTP.com', 'wp-mail-smtp' )
|
||||
);
|
||||
}
|
||||
|
||||
$description .= '<p class="wp-mail-smtp-tooltip">' .
|
||||
esc_html__( 'Transparency and Disclosure', 'wp-mail-smtp' ) .
|
||||
'<span class="wp-mail-smtp-tooltip-text">' .
|
||||
esc_html__( 'We believe in full transparency. The SMTP.com links above are tracking links as part of our partnership with SMTP (j2 Global). We can recommend just about any SMTP service, but we only recommend products that we believe will add value to our users.', 'wp-mail-smtp' ) .
|
||||
'</span></p>';
|
||||
|
||||
parent::__construct(
|
||||
[
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/smtp-com.svg',
|
||||
'slug' => self::SLUG,
|
||||
'title' => esc_html__( 'SMTP.com', 'wp-mail-smtp' ),
|
||||
'description' => $description,
|
||||
'recommended' => true,
|
||||
'supports' => [
|
||||
'from_email' => true,
|
||||
'from_name' => true,
|
||||
'return_path' => false,
|
||||
'from_email_force' => true,
|
||||
'from_name_force' => true,
|
||||
],
|
||||
],
|
||||
$connection
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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">
|
||||
<?php if ( $this->connection_options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_SMTPCOM_API_KEY' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %s - API key link. */
|
||||
esc_html__( 'Follow this link to get an API Key from SMTP.com: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://my.smtp.com/settings/api" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Channel/Sender -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-channel" 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() ); ?>-channel"><?php esc_html_e( 'Sender 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() ); ?>][channel]" type="text"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'channel' ) ); ?>"
|
||||
<?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'channel' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-channel" spellcheck="false"
|
||||
/>
|
||||
<?php
|
||||
if ( $this->connection_options->is_const_defined( $this->get_slug(), 'channel' ) ) {
|
||||
$this->display_const_set_message( 'WPMS_SMTPCOM_CHANNEL' );
|
||||
}
|
||||
?>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %s - Channel/Sender Name link for smtp.com documentation. */
|
||||
esc_html__( 'Follow this link to get a Sender Name from SMTP.com: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://my.smtp.com/senders/" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get Sender Name', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -1,398 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendgrid;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\MailCatcherInterface;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 202;
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://api.sendgrid.com/v3/mail/send';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $phpmailer, $connection = null ) {
|
||||
|
||||
// We want to prefill everything from MailCatcher class, which extends PHPMailer.
|
||||
parent::__construct( $phpmailer, $connection );
|
||||
|
||||
$this->set_header( 'Authorization', 'Bearer ' . $this->connection_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/html';
|
||||
$data['value'] = $content;
|
||||
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$data['type'] = 'text/plain';
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'content' => array( $data ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are processed for this mailer - they should be in body.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param array $headers
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
$this->set_body_header( $name, $value );
|
||||
}
|
||||
|
||||
// Add custom PHPMailer-specific header.
|
||||
$this->set_body_header( 'X-Mailer', 'WPMailSMTP/Mailer/' . $this->mailer . ' ' . WPMS_PLUGIN_VER );
|
||||
}
|
||||
|
||||
/**
|
||||
* This mailer supports email-related custom headers inside a body of the message.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function set_body_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
if ( empty( $name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$headers = isset( $this->body['headers'] ) ? (array) $this->body['headers'] : array();
|
||||
|
||||
$headers[ $name ] = WP::sanitize_value( $value );
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'headers' => $headers,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 by SendGrid API.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $attachments The array of attachments data.
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = $this->get_attachment_file_content( $attachment );
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filetype = str_replace( ';', '', trim( $attachment[4] ) );
|
||||
|
||||
$data[] = [
|
||||
'content' => base64_encode( $file ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
||||
'type' => $filetype, // string, no ;, no CRLF.
|
||||
'filename' => $this->get_attachment_file_name( $attachment ), // required string, no CRLF.
|
||||
'disposition' => in_array( $attachment[6], [ 'inline', 'attachment' ], true ) ? $attachment[6] : 'attachment', // either inline or attachment.
|
||||
'content_id' => empty( $attachment[7] ) ? '' : trim( (string) $attachment[7] ), // string, no CRLF.
|
||||
];
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'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;
|
||||
}
|
||||
}
|
||||
|
||||
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 $from_email
|
||||
*/
|
||||
public function set_return_path( $from_email ) {}
|
||||
|
||||
/**
|
||||
* Get a SendGrid-specific response with a helpful error.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_response_error() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh, Generic.Metrics.NestingLevel.MaxExceeded
|
||||
|
||||
$error_text[] = $this->error_message;
|
||||
|
||||
if ( ! empty( $this->response ) ) {
|
||||
$body = wp_remote_retrieve_body( $this->response );
|
||||
|
||||
if ( ! empty( $body->errors ) && is_array( $body->errors ) ) {
|
||||
foreach ( $body->errors as $error ) {
|
||||
if ( ! empty( $error->message ) ) {
|
||||
$message = $error->message;
|
||||
$code = ! empty( $error->field ) ? $error->field : '';
|
||||
$description = ! empty( $error->help ) ? $error->help : '';
|
||||
|
||||
$error_text[] = Helpers::format_error_message( $message, $code, $description );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error_text[] = WP::wp_remote_get_response_error_message( $this->response );
|
||||
}
|
||||
}
|
||||
|
||||
return implode( WP::EOL, array_map( 'esc_textarea', array_filter( $error_text ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mailer debug information, that is helpful during support.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$sendgrid_text[] = '<strong>Api Key:</strong> ' . ( $this->is_mailer_complete() ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $sendgrid_text );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
// API key is the only required option.
|
||||
if ( ! empty( $options['api_key'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendgrid;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Option.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 2.3.0 Added supports parameter.
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $connection = null ) {
|
||||
|
||||
parent::__construct(
|
||||
[
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/sendgrid.svg',
|
||||
'slug' => 'sendgrid',
|
||||
'title' => esc_html__( 'SendGrid', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses(
|
||||
/* translators: %1$s - URL to sendgrid.com; %2$s - URL to Sendgrid documentation on wpmailsmtp.com */
|
||||
__( '<a href="%1$s" target="_blank" rel="noopener noreferrer">SendGrid</a> is a popular transactional email provider that sends more than 35 billion emails every month. If you\'re just starting out, the free plan allows you to send up to 100 emails each day without entering your credit card details.<br><br>To get started, read our <a href="%2$s" target="_blank" rel="noopener noreferrer">SendGrid documentation</a>.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'br' => [],
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
),
|
||||
'https://sendgrid.com',
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-sendgrid-mailer-in-wp-mail-smtp/', 'SendGrid documentation' ) )
|
||||
),
|
||||
'supports' => [
|
||||
'from_email' => true,
|
||||
'from_name' => true,
|
||||
'return_path' => false,
|
||||
'from_email_force' => true,
|
||||
'from_name_force' => true,
|
||||
],
|
||||
],
|
||||
$connection
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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">
|
||||
<?php if ( $this->connection_options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_SENDGRID_API_KEY' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
<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>
|
||||
|
||||
<!-- Sending 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( 'Sending Domain', '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->connection_options->get( $this->get_slug(), 'domain' ) ); ?>"
|
||||
<?php echo $this->connection_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(
|
||||
wp_kses(
|
||||
/* translators: %s - URL to SendGrid documentation on wpmailsmtp.com */
|
||||
__( 'Please input the sending domain/subdomain you configured in your SendGrid dashboard. More information can be found in our <a href="%s" target="_blank" rel="noopener noreferrer">SendGrid documentation</a>.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'br' => [],
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
),
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-sendgrid-mailer-in-wp-mail-smtp/#setup', 'SendGrid documentation - setup' ) )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendinblue;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
|
||||
/**
|
||||
* Class Api is a wrapper for Sendinblue library with handy methods.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class Api {
|
||||
|
||||
/**
|
||||
* The Connection object.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @var ConnectionInterface
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* Contains mailer options, constants + DB values.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* API constructor that inits defaults and retrieves options.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $connection = null ) {
|
||||
|
||||
if ( ! is_null( $connection ) ) {
|
||||
$this->connection = $connection;
|
||||
} else {
|
||||
$this->connection = wp_mail_smtp()->get_connections_manager()->get_primary_connection();
|
||||
}
|
||||
|
||||
$this->options = $this->connection->get_options()->get_group( Options::SLUG );
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure API key authorization: api-key.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @deprecated 3.9.0 We are no longer using the Sendinblue SDK.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function get_api_config() {
|
||||
|
||||
_deprecated_function( __METHOD__, '3.9.0' );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mailer client instance for Account API.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @deprecated 3.9.0 We are no longer using the Sendinblue SDK.
|
||||
*/
|
||||
public function get_account_client() {
|
||||
|
||||
_deprecated_function( __METHOD__, '3.9.0' );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mailer client instance for Sender API.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @deprecated 3.9.0 We are no longer using the Sendinblue SDK.
|
||||
*/
|
||||
public function get_sender_client() {
|
||||
|
||||
_deprecated_function( __METHOD__, '3.9.0' );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mailer client instance for SMTP API.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @deprecated 3.9.0 We are no longer using the Sendinblue SDK.
|
||||
*/
|
||||
public function get_smtp_client() {
|
||||
|
||||
_deprecated_function( __METHOD__, '3.9.0' );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the mailer is ready to be used in API calls.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_ready() {
|
||||
|
||||
return ! empty( $this->options['api_key'] );
|
||||
}
|
||||
}
|
||||
@@ -1,454 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendinblue;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\MailCatcherInterface;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 201;
|
||||
|
||||
/**
|
||||
* Response code for scheduled email.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_scheduled_code = 202;
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @since 3.9.0 Update to use Brevo API.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://api.brevo.com/v3/smtp/email';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $phpmailer, $connection = null ) {
|
||||
|
||||
parent::__construct( $phpmailer, $connection );
|
||||
|
||||
$this->set_header( 'api-key', $this->connection_options->get( $this->mailer, 'api_key' ) );
|
||||
$this->set_header( 'Accept', 'application/json' );
|
||||
$this->set_header( 'content-type', 'application/json' );
|
||||
}
|
||||
|
||||
/**
|
||||
* The list of allowed attachment files extensions.
|
||||
*
|
||||
* @see https://developers.sendinblue.com/reference#sendTransacEmail_attachment__title
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
// @formatter:off
|
||||
protected $allowed_attach_ext = array( 'xlsx', 'xls', 'ods', 'docx', 'docm', 'doc', 'csv', 'pdf', 'txt', 'gif', 'jpg', 'jpeg', 'png', 'tif', 'tiff', 'rtf', 'bmp', 'cgm', 'css', 'shtml', 'html', 'htm', 'zip', 'xml', 'ppt', 'pptx', 'tar', 'ez', 'ics', 'mobi', 'msg', 'pub', 'eps', 'odt', 'mp3', 'm4a', 'm4v', 'wma', 'ogg', 'flac', 'wav', 'aif', 'aifc', 'aiff', 'mp4', 'mov', 'avi', 'mkv', 'mpeg', 'mpg', 'wmv' );
|
||||
// @formatter:on
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are processed for this mailer - they should be in body.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param array $headers List of key=>value pairs.
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
$this->set_body_header( $name, $value );
|
||||
}
|
||||
|
||||
// Add custom PHPMailer-specific header.
|
||||
$this->set_body_header( 'X-Mailer', 'WPMailSMTP/Mailer/' . $this->mailer . ' ' . WPMS_PLUGIN_VER );
|
||||
}
|
||||
|
||||
/**
|
||||
* This mailer supports email-related custom headers inside a body of the message.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param string $name Key.
|
||||
* @param string $value Value.
|
||||
*/
|
||||
public function set_body_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$headers = isset( $this->body['headers'] ) ? (array) $this->body['headers'] : [];
|
||||
$headers[ $name ] = WP::sanitize_value( $value );
|
||||
|
||||
$this->set_body_param(
|
||||
[
|
||||
'headers' => $headers,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the From information for an email.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param string $email
|
||||
* @param string $name
|
||||
*/
|
||||
public function set_from( $email, $name ) {
|
||||
|
||||
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->body['sender'] = array(
|
||||
'email' => $email,
|
||||
'name' => ! empty( $name ) ? WP::sanitize_value( $name ) : '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email recipients: to, cc, bcc.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param array $recipients
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $data as $type => $type_recipients ) {
|
||||
$this->body[ $type ] = $type_recipients;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function set_subject( $subject ) {
|
||||
|
||||
$this->body['subject'] = $subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email content.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param string|array $content
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_array( $content ) ) {
|
||||
|
||||
if ( ! empty( $content['text'] ) ) {
|
||||
$this->body['textContent'] = $content['text'];
|
||||
}
|
||||
|
||||
if ( ! empty( $content['html'] ) ) {
|
||||
$this->body['htmlContent'] = $content['html'];
|
||||
}
|
||||
} else {
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$this->body['textContent'] = $content;
|
||||
} else {
|
||||
$this->body['htmlContent'] = $content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't support this.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param string $email
|
||||
*/
|
||||
public function set_return_path( $email ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Reply To headers if not set already.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param array $emails
|
||||
*/
|
||||
public function set_reply_to( $emails ) {
|
||||
|
||||
if ( empty( $emails ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $emails as $user ) {
|
||||
$holder = array();
|
||||
$addr = isset( $user[0] ) ? $user[0] : false;
|
||||
$name = isset( $user[1] ) ? $user[1] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$holder['email'] = $addr;
|
||||
if ( ! empty( $name ) ) {
|
||||
$holder['name'] = $name;
|
||||
}
|
||||
|
||||
$data[] = $holder;
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->body['replyTo'] = $data[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attachments for an email.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param array $attachments The array of attachments data.
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
|
||||
$ext = pathinfo( $attachment[1], PATHINFO_EXTENSION );
|
||||
|
||||
if ( ! in_array( $ext, $this->allowed_attach_ext, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$file = $this->get_attachment_file_content( $attachment );
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->body['attachment'][] = [
|
||||
'name' => $this->get_attachment_file_name( $attachment ),
|
||||
'content' => base64_encode( $file ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the email body.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @since 3.9.0 Returns email body array instead of `SendSmtpEmail` object.
|
||||
* @since 3.10.0 Returns JSON encoded email body instead of array.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
/**
|
||||
* Filters Sendinblue email body.
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @param array $body Email body.
|
||||
*/
|
||||
$body = apply_filters( 'wp_mail_smtp_providers_sendinblue_mailer_get_body', $this->body );
|
||||
|
||||
return wp_json_encode( $body );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.6.0
|
||||
* @since 3.9.0 Expect a generic class object instead of `CreateSmtpEmail`.
|
||||
*
|
||||
* @param mixed $response Response from the API.
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
parent::process_response( $response );
|
||||
|
||||
if ( $this->has_message_id() ) {
|
||||
$this->phpmailer->MessageID = $this->response['body']->messageId;
|
||||
$this->verify_sent_status = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Sendinblue-specific response with a helpful error.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_response_error() {
|
||||
|
||||
$error_text = [];
|
||||
|
||||
if ( ! empty( $this->error_message ) ) {
|
||||
$error_text[] = $this->error_message;
|
||||
}
|
||||
|
||||
if ( ! empty( $this->response ) ) {
|
||||
$body = wp_remote_retrieve_body( $this->response );
|
||||
|
||||
if ( ! empty( $body->message ) ) {
|
||||
$error_text[] = Helpers::format_error_message( $body->message, ! empty( $body->code ) ? $body->code : '' );
|
||||
} else {
|
||||
$error_text[] = WP::wp_remote_get_response_error_message( $this->response );
|
||||
}
|
||||
}
|
||||
|
||||
return implode( WP::EOL, array_map( 'esc_textarea', array_filter( $error_text ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the response has `messageId` property.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function has_message_id() {
|
||||
|
||||
if (
|
||||
! in_array(
|
||||
wp_remote_retrieve_response_code( $this->response ),
|
||||
[ $this->email_sent_code, $this->email_scheduled_code ],
|
||||
true
|
||||
) ||
|
||||
empty( $this->response['body']->messageId )
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the email was sent.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @since 3.9.0 Check if `$this->response` has `messageId` property to check if the email was sent.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_email_sent() {
|
||||
|
||||
/** This filter is documented in src/Providers/MailerAbstract.php. */
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_is_email_sent', $this->has_message_id(), $this->mailer ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$mailjet_text[] = '<strong>API Key:</strong> ' . ( $this->is_mailer_complete() ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $mailjet_text );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
// API key is the only required option.
|
||||
if ( ! empty( $options['api_key'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendinblue;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
const SLUG = 'sendinblue';
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @since 2.3.0 Added supports parameter.
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $connection = null ) {
|
||||
|
||||
if ( is_null( $connection ) ) {
|
||||
$connection = wp_mail_smtp()->get_connections_manager()->get_primary_connection();
|
||||
}
|
||||
|
||||
$description = sprintf(
|
||||
wp_kses( /* translators: %1$s - URL to brevo.com site. */
|
||||
__( '<strong><a href="%1$s" target="_blank" rel="noopener noreferrer">Brevo</a> (formerly Sendinblue) is one of our recommended mailers.</strong> It\'s a transactional email provider with scalable price plans, so it\'s suitable for any size of business.<br><br>If you\'re just starting out, you can use Brevo\'s free plan to send up to 300 emails a day. You don\'t need to use a credit card to try it out. When you\'re ready, you can upgrade to a higher plan to increase your sending limits.', 'wp-mail-smtp' ) .
|
||||
'<br><br>' .
|
||||
/* translators: %2$s - URL to wpmailsmtp.com doc. */
|
||||
__( 'To get started, read our <a href="%2$s" target="_blank" rel="noopener noreferrer">Brevo documentation</a>.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'strong' => true,
|
||||
'br' => true,
|
||||
'a' => [
|
||||
'href' => true,
|
||||
'rel' => true,
|
||||
'target' => true,
|
||||
],
|
||||
]
|
||||
),
|
||||
'https://wpmailsmtp.com/go/sendinblue/',
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-sendinblue-mailer-in-wp-mail-smtp/', 'Brevo documentation' ) )
|
||||
);
|
||||
|
||||
$api_key = $connection->get_options()->get( self::SLUG, 'api_key' );
|
||||
|
||||
if ( empty( $api_key ) ) {
|
||||
$description .= sprintf(
|
||||
'</p><p class="buttonned"><a href="%1$s" target="_blank" rel="noopener noreferrer" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-blueish">%2$s</a></p>',
|
||||
'https://wpmailsmtp.com/go/sendinblue/',
|
||||
esc_html__( 'Get Brevo Now (Free)', 'wp-mail-smtp' )
|
||||
);
|
||||
}
|
||||
|
||||
$description .= '<p class="wp-mail-smtp-tooltip">' .
|
||||
esc_html__( 'Transparency and Disclosure', 'wp-mail-smtp' ) .
|
||||
'<span class="wp-mail-smtp-tooltip-text">' .
|
||||
esc_html__( 'We believe in full transparency. The Brevo (formerly Sendinblue) links above are tracking links as part of our partnership with Brevo. We can recommend just about any SMTP service, but we only recommend products that we believe will add value to our users.', 'wp-mail-smtp' ) .
|
||||
'</span></p>';
|
||||
|
||||
parent::__construct(
|
||||
[
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/brevo.svg',
|
||||
'slug' => self::SLUG,
|
||||
'title' => esc_html__( 'Brevo', 'wp-mail-smtp' ),
|
||||
'php' => '5.6',
|
||||
'description' => $description,
|
||||
'supports' => [
|
||||
'from_email' => true,
|
||||
'from_name' => true,
|
||||
'return_path' => false,
|
||||
'from_email_force' => true,
|
||||
'from_name_force' => true,
|
||||
],
|
||||
'recommended' => true,
|
||||
],
|
||||
$connection
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the mailer provider options.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
// Do not display options if PHP version is not correct.
|
||||
if ( ! $this->is_php_correct() ) {
|
||||
$this->display_php_warning();
|
||||
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- API Key -->
|
||||
<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() ); ?>-api_key"><?php esc_html_e( 'API Key', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->connection_options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_SENDINBLUE_API_KEY' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %s - link to get an API Key. */
|
||||
esc_html__( 'Follow this link to get an API Key: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://app.brevo.com/settings/keys/api" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get v3 API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sending 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( 'Sending Domain', '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->connection_options->get( $this->get_slug(), 'domain' ) ); ?>"
|
||||
<?php echo $this->connection_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(
|
||||
wp_kses(
|
||||
/* translators: %s - URL to Sendinblue documentation on wpmailsmtp.com */
|
||||
__( 'Please input the sending domain/subdomain you configured in your Brevo (formerly Sendinblue) dashboard. More information can be found in our <a href="%s" target="_blank" rel="noopener noreferrer">Brevo documentation</a>.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'br' => [],
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
),
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-sendinblue-mailer-in-wp-mail-smtp/#setup-smtp', 'Brevo documentation' ) )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -1,453 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendlayer;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\WP;
|
||||
use WPMailSMTP\MailCatcherInterface;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://console.sendlayer.com/api/v1/email';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $phpmailer, $connection = null ) {
|
||||
|
||||
// We want to prefill everything from MailCatcher class, which extends PHPMailer.
|
||||
parent::__construct( $phpmailer, $connection );
|
||||
|
||||
// Set mailer specific headers.
|
||||
$this->set_header( 'Authorization', 'Bearer ' . $this->connection_options->get( $this->mailer, 'api_key' ) );
|
||||
$this->set_header( 'Accept', 'application/json' );
|
||||
$this->set_header( 'Content-Type', 'application/json' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are processed for this mailer - they should be in body.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param array $headers Headers array.
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
$this->set_body_header( $name, $value );
|
||||
}
|
||||
|
||||
// Add custom header.
|
||||
$this->set_body_header( 'X-Mailer', 'WPMailSMTP/Mailer/' . $this->mailer . ' ' . WPMS_PLUGIN_VER );
|
||||
}
|
||||
|
||||
/**
|
||||
* This mailer supports email-related custom headers inside a body of the message.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param string $name Header name.
|
||||
* @param string $value Header value.
|
||||
*/
|
||||
public function set_body_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$headers = isset( $this->body['Headers'] ) ? (array) $this->body['Headers'] : [];
|
||||
|
||||
$headers[ $name ] = WP::sanitize_value( $value );
|
||||
|
||||
$this->set_body_param(
|
||||
[
|
||||
'Headers' => $headers,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the From information for an email.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param string $email The sender email address.
|
||||
* @param string $name The sender name.
|
||||
*/
|
||||
public function set_from( $email, $name ) {
|
||||
|
||||
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
[
|
||||
'From' => $this->address_format( [ $email, $name ] ),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email recipients: to, cc, bcc.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param array $recipients Email recipients.
|
||||
*/
|
||||
public function set_recipients( $recipients ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
|
||||
if ( empty( $recipients ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Allow only these recipient types.
|
||||
$allowed_types = [ 'to', 'cc', 'bcc' ];
|
||||
$data = [];
|
||||
|
||||
foreach ( $recipients as $type => $emails ) {
|
||||
if (
|
||||
! in_array( $type, $allowed_types, true ) ||
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = ucfirst( $type );
|
||||
|
||||
// Iterate over all emails for each type.
|
||||
// There might be multiple cc/to/bcc emails.
|
||||
foreach ( $emails as $email ) {
|
||||
if ( ! isset( $email[0] ) || ! filter_var( $email[0], FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[ $type ][] = $this->address_format( $email );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param( $data );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Reply To information for an email.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param array $emails Reply To email addresses.
|
||||
*/
|
||||
public function set_reply_to( $emails ) {
|
||||
|
||||
if ( empty( $emails ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $emails as $email ) {
|
||||
if ( ! isset( $email[0] ) || ! filter_var( $email[0], FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = $this->address_format( $email );
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'ReplyTo' => $data,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email subject.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param string $subject Email subject.
|
||||
*/
|
||||
public function set_subject( $subject ) {
|
||||
|
||||
$this->set_body_param(
|
||||
[
|
||||
'Subject' => $subject,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email content.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param string|array $content Email content.
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_array( $content ) ) {
|
||||
if ( ! empty( $content['text'] ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'ContentType' => 'plain',
|
||||
'PlainContent' => $content['text'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $content['html'] ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'ContentType' => 'html',
|
||||
'HTMLContent' => $content['html'],
|
||||
]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'ContentType' => 'plain',
|
||||
'PlainContent' => $content,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'ContentType' => 'html',
|
||||
'HTMLContent' => $content,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attachments for an email.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param array $attachments Attachments array.
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $this->prepare_attachments( $attachments );
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'Attachments' => $data,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare attachments data for SendLayer API.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param array $attachments Array of attachments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepare_attachments( $attachments ) {
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = $this->get_attachment_file_content( $attachment );
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filetype = str_replace( ';', '', trim( $attachment[4] ) );
|
||||
|
||||
$data[] = [
|
||||
'Filename' => empty( $attachment[2] ) ? 'file-' . wp_hash( microtime() ) . '.' . $filetype : trim( $attachment[2] ),
|
||||
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
||||
'Content' => base64_encode( $file ),
|
||||
'Type' => $attachment[4],
|
||||
'Disposition' => in_array( $attachment[6], [ 'inline', 'attachment' ], true ) ? $attachment[6] : 'attachment',
|
||||
'ContentId' => empty( $attachment[7] ) ? '' : trim( (string) $attachment[7] ),
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't support this.
|
||||
* So we do nothing.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param string $email Return Path email address.
|
||||
*/
|
||||
public function set_return_path( $email ) { }
|
||||
|
||||
/**
|
||||
* Redefine the way email body is returned.
|
||||
* By default, we are sending an array of data.
|
||||
* SendLayer requires a JSON, so we encode the body.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
$body = parent::get_body();
|
||||
|
||||
return wp_json_encode( $body );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 3.4.0
|
||||
*
|
||||
* @param mixed $response Response data.
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
parent::process_response( $response );
|
||||
|
||||
if (
|
||||
! is_wp_error( $response ) &&
|
||||
! empty( $this->response['body']->MessageID )
|
||||
) {
|
||||
$this->phpmailer->addCustomHeader( 'X-Msg-ID', $this->response['body']->MessageID );
|
||||
$this->verify_sent_status = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a SendLayer-specific response with a helpful error.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_response_error() { // phpcs:ignore Generic.Metrics.NestingLevel.MaxExceeded
|
||||
|
||||
$error_text[] = $this->error_message;
|
||||
|
||||
if ( ! empty( $this->response ) ) {
|
||||
$body = wp_remote_retrieve_body( $this->response );
|
||||
|
||||
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||
if ( ! empty( $body->Errors ) && is_array( $body->Errors ) ) {
|
||||
foreach ( $body->Errors as $error ) {
|
||||
if ( ! empty( $error->Message ) ) {
|
||||
$message = $error->Message;
|
||||
$code = ! empty( $error->Code ) ? $error->Code : '';
|
||||
|
||||
$error_text[] = Helpers::format_error_message( $message, $code );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error_text[] = WP::wp_remote_get_response_error_message( $this->response );
|
||||
}
|
||||
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
|
||||
}
|
||||
|
||||
return implode( WP::EOL, array_map( 'esc_textarea', array_filter( $error_text ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mailer debug information, that is helpful during support.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$options = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
$text[] = '<strong>' . esc_html__( 'API Key:', 'wp-mail-smtp' ) . '</strong> ' .
|
||||
( ! empty( $options['api_key'] ) ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the mailer has all its settings correctly set up and saved.
|
||||
*
|
||||
* This mailer is configured when `server_api_token` setting is defined.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
if ( ! empty( $options['api_key'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare address param.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param array $address Address array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function address_format( $address ) {
|
||||
|
||||
$result = [];
|
||||
$email = isset( $address[0] ) ? $address[0] : false;
|
||||
$name = isset( $address[1] ) ? $address[1] : false;
|
||||
|
||||
$result['Email'] = $email;
|
||||
|
||||
if ( ! empty( $name ) ) {
|
||||
$result['Name'] = $name;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendlayer;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SLUG = 'sendlayer';
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $connection = null ) {
|
||||
|
||||
if ( is_null( $connection ) ) {
|
||||
$connection = wp_mail_smtp()->get_connections_manager()->get_primary_connection();
|
||||
}
|
||||
|
||||
$description = sprintf(
|
||||
wp_kses(
|
||||
/* translators: %1$s - URL to sendlayer.com; %2$s - URL to SendLayer documentation on wpmailsmtp.com. */
|
||||
__( '<strong><a href="%1$s" target="_blank" rel="noopener noreferrer">SendLayer</a> is our #1 recommended mailer.</strong> Its affordable pricing and simple setup make it the perfect choice for WordPress sites. SendLayer will authenticate your outgoing emails to make sure they always hit customers’ inboxes, and it has detailed documentation to help you authorize your domain.<br><br>You can send hundreds of emails for free when you sign up for a trial.<br><br>To get started, read our <a href="%2$s" target="_blank" rel="noopener noreferrer">SendLayer documentation</a>.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'strong' => [],
|
||||
'br' => [],
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
),
|
||||
// phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound, WordPress.Security.NonceVerification.Recommended
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://sendlayer.com/wp-mail-smtp/', [ 'source' => 'wpmailsmtpplugin', 'medium' => 'WordPress', 'content' => isset( $_GET['page'] ) && $_GET['page'] === 'wp-mail-smtp-setup-wizard' ? 'Setup Wizard - Mailer Description' : 'Plugin Settings - Mailer Description' ] ) ),
|
||||
// phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-sendlayer-mailer-in-wp-mail-smtp/', 'SendLayer Documentation' ) )
|
||||
);
|
||||
|
||||
$mailer_options = $connection->get_options()->get_group( self::SLUG );
|
||||
|
||||
if ( empty( $mailer_options['api_key'] ) ) {
|
||||
$description .= sprintf(
|
||||
'</p><p class="buttonned"><a href="%1$s" target="_blank" rel="noopener noreferrer" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-blueish">%2$s</a></p>',
|
||||
// phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://sendlayer.com/wp-mail-smtp/', [ 'source' => 'wpmailsmtpplugin', 'medium' => 'WordPress', 'content' => 'Plugin Settings - Mailer Button' ] ) ),
|
||||
esc_html__( 'Get Started with SendLayer', 'wp-mail-smtp' )
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct(
|
||||
[
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/sendlayer.svg',
|
||||
'slug' => self::SLUG,
|
||||
'title' => esc_html__( 'SendLayer', 'wp-mail-smtp' ),
|
||||
'description' => $description,
|
||||
'recommended' => true,
|
||||
],
|
||||
$connection
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the mailer provider options.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
// phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound, WordPress.Security.NonceVerification.Recommended
|
||||
$get_api_key_url = wp_mail_smtp()->get_utm_url( 'https://app.sendlayer.com/settings/api/', [ 'source' => 'wpmailsmtpplugin', 'medium' => 'WordPress', 'content' => 'Plugin Settings - Get API Key' ] );
|
||||
?>
|
||||
|
||||
<!-- 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">
|
||||
<?php if ( $this->connection_options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_SENDLAYER_API_KEY' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - API key link. */
|
||||
esc_html__( 'Follow this link to get an API Key from SendLayer: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="' . esc_url( $get_api_key_url ) . '" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -1,542 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SparkPost;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\WP;
|
||||
use WPMailSMTP\MailCatcherInterface;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
|
||||
/**
|
||||
* Class Mailer.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* API endpoint used for sites from all regions.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const API_BASE_US = 'https://api.sparkpost.com/api/v1';
|
||||
|
||||
/**
|
||||
* API endpoint used for sites from EU region.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const API_BASE_EU = 'https://api.eu.sparkpost.com/api/v1';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $phpmailer, $connection = null ) {
|
||||
|
||||
// Default value should be defined before the parent class constructor fires.
|
||||
$this->url = self::API_BASE_US;
|
||||
|
||||
// We want to prefill everything from MailCatcher class, which extends PHPMailer.
|
||||
parent::__construct( $phpmailer, $connection );
|
||||
|
||||
// We have a special API URL to query in case of EU region.
|
||||
if ( $this->connection_options->get( $this->mailer, 'region' ) === 'EU' ) {
|
||||
$this->url = self::API_BASE_EU;
|
||||
}
|
||||
|
||||
$this->url .= '/transmissions';
|
||||
|
||||
// Set mailer specific headers.
|
||||
$this->set_header( 'Authorization', $this->connection_options->get( $this->mailer, 'api_key' ) );
|
||||
$this->set_header( 'Content-Type', 'application/json' );
|
||||
|
||||
// Set default body params.
|
||||
$this->set_body_param(
|
||||
[
|
||||
'options' => [
|
||||
'open_tracking' => false,
|
||||
'click_tracking' => false,
|
||||
'transactional' => true,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters return path.
|
||||
*
|
||||
* Email address to use for envelope FROM.
|
||||
* The domain of the return_path address must be a CNAME-verified sending domain.
|
||||
* The local part of the return_path address will be overwritten by SparkPost.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param string $return_path Email address, by default will be used value configured in SparkPost dashboard.
|
||||
*/
|
||||
$return_path = apply_filters( 'wp_mail_smtp_providers_sparkpost_mailer_return_path', '' );
|
||||
|
||||
if ( $return_path && filter_var( $return_path, FILTER_VALIDATE_EMAIL ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'return_path' => $return_path,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are processed for this mailer - they should be in body.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param array $headers Headers array.
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
$this->set_body_header( $name, $value );
|
||||
}
|
||||
|
||||
// Add custom PHPMailer-specific header.
|
||||
$this->set_body_header( 'X-Mailer', 'WPMailSMTP/Mailer/' . $this->mailer . ' ' . WPMS_PLUGIN_VER );
|
||||
$this->set_body_header( 'Message-ID', $this->phpmailer->getLastMessageID() );
|
||||
}
|
||||
|
||||
/**
|
||||
* This mailer supports email-related custom headers inside a body of the message.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param string $name Header name.
|
||||
* @param string $value Header value.
|
||||
*/
|
||||
public function set_body_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$headers = isset( $this->body['content']['headers'] ) ? (array) $this->body['content']['headers'] : [];
|
||||
|
||||
if ( ! in_array( $name, [ 'Message-ID', 'CC' ], true ) ) {
|
||||
$value = WP::sanitize_value( $value );
|
||||
}
|
||||
|
||||
$headers[ $name ] = $value;
|
||||
|
||||
$this->set_body_param(
|
||||
[
|
||||
'content' => [
|
||||
'headers' => $headers,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the From information for an email.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param string $email The sender email address.
|
||||
* @param string $name The sender name.
|
||||
*/
|
||||
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(
|
||||
[
|
||||
'content' => [
|
||||
'from' => $from,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email recipients: to, cc, bcc.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param array $recipients Email recipients.
|
||||
*/
|
||||
public function set_recipients( $recipients ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
|
||||
if ( empty( $recipients ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$recipients_to = isset( $recipients['to'] ) && is_array( $recipients['to'] ) ? $recipients['to'] : [];
|
||||
$header_to = implode( ',', array_map( [ $this->phpmailer, 'addrFormat' ], $recipients_to ) );
|
||||
|
||||
$default = [ 'to', 'cc', 'bcc' ];
|
||||
|
||||
foreach ( $recipients as $type => $emails ) {
|
||||
if (
|
||||
! in_array( $type, $default, true ) ||
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $emails as $email ) {
|
||||
$addr = isset( $email[0] ) ? $email[0] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = [
|
||||
'address' => $this->build_recipient( $email, $header_to ),
|
||||
];
|
||||
}
|
||||
|
||||
// CC recipients must be also included as header.
|
||||
if ( $type === 'cc' ) {
|
||||
$this->set_body_header( 'CC', implode( ',', array_map( [ $this->phpmailer, 'addrFormat' ], $emails ) ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'recipients' => $data,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Reply To information for an email.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param array $emails Reply To email addresses.
|
||||
*/
|
||||
public function set_reply_to( $emails ) {
|
||||
|
||||
if ( empty( $emails ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $emails as $email ) {
|
||||
$addr = isset( $email[0] ) ? $email[0] : false;
|
||||
|
||||
if ( ! filter_var( $addr, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = $this->phpmailer->addrFormat( $email );
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'content' => [
|
||||
'reply_to' => implode( ',', $data ),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email subject.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param string $subject Email subject.
|
||||
*/
|
||||
public function set_subject( $subject ) {
|
||||
|
||||
$this->set_body_param(
|
||||
[
|
||||
'content' => [
|
||||
'subject' => $subject,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email content.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param string|array $content Email content.
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_array( $content ) ) {
|
||||
if ( ! empty( $content['text'] ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'content' => [
|
||||
'text' => $content['text'],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $content['html'] ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'content' => [
|
||||
'html' => $content['html'],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'content' => [
|
||||
'text' => $content,
|
||||
],
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'content' => [
|
||||
'html' => $content,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attachments for an email.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param array $attachments Attachments array.
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $this->prepare_attachments( $attachments );
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
[
|
||||
'content' => [
|
||||
'attachments' => $data,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare attachments data for SparkPost API.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param array $attachments Array of attachments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepare_attachments( $attachments ) {
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = $this->get_attachment_file_content( $attachment );
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = [
|
||||
'name' => $this->get_attachment_file_name( $attachment ),
|
||||
'data' => base64_encode( $file ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
||||
'type' => $attachment[4],
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't support this.
|
||||
* Return path can be configured in SparkPost account.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param string $email Return Path email address.
|
||||
*/
|
||||
public function set_return_path( $email ) { }
|
||||
|
||||
/**
|
||||
* Redefine the way email body is returned.
|
||||
* By default, we are sending an array of data.
|
||||
* SparkPost requires a JSON, so we encode the body.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
$body = parent::get_body();
|
||||
|
||||
return wp_json_encode( $body );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 3.2.0
|
||||
*
|
||||
* @param mixed $response Response data.
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
parent::process_response( $response );
|
||||
|
||||
if (
|
||||
! is_wp_error( $response ) &&
|
||||
! empty( $this->response['body']->results->id )
|
||||
) {
|
||||
$this->phpmailer->addCustomHeader( 'X-Msg-ID', $this->response['body']->results->id );
|
||||
$this->verify_sent_status = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a SparkPost-specific response with a helpful error.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_response_error() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh, Generic.Metrics.NestingLevel.MaxExceeded
|
||||
|
||||
$error_text[] = $this->error_message;
|
||||
|
||||
if ( ! empty( $this->response ) ) {
|
||||
$body = wp_remote_retrieve_body( $this->response );
|
||||
|
||||
if ( ! empty( $body->errors ) && is_array( $body->errors ) ) {
|
||||
foreach ( $body->errors as $error ) {
|
||||
if ( ! empty( $error->message ) ) {
|
||||
$message = $error->message;
|
||||
$code = ! empty( $error->code ) ? $error->code : '';
|
||||
$description = ! empty( $error->description ) ? $error->description : '';
|
||||
|
||||
$error_text[] = Helpers::format_error_message( $message, $code, $description );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error_text[] = WP::wp_remote_get_response_error_message( $this->response );
|
||||
}
|
||||
}
|
||||
|
||||
return implode( WP::EOL, array_map( 'esc_textarea', array_filter( $error_text ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mailer debug information, that is helpful during support.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$options = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
$text[] = '<strong>' . esc_html__( 'API Key:', 'wp-mail-smtp' ) . '</strong> ' .
|
||||
( ! empty( $options['api_key'] ) ? 'Yes' : 'No' );
|
||||
$text[] = '<strong>' . esc_html__( 'Region:', 'wp-mail-smtp' ) . '</strong> ' .
|
||||
( ! empty( $options['region'] ) ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the mailer has all its settings correctly set up and saved.
|
||||
*
|
||||
* This mailer is configured when `api_key` setting is defined.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->connection_options->get_group( $this->mailer );
|
||||
|
||||
if ( ! empty( $options['api_key'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build recipient array.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param array $address Email address array.
|
||||
* @param string $header_to Email recipients To header.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function build_recipient( $address, $header_to ) {
|
||||
|
||||
$holder = [];
|
||||
|
||||
$holder['email'] = $address[0];
|
||||
|
||||
if ( ! empty( $address[1] ) ) {
|
||||
$holder['name'] = $address[1];
|
||||
}
|
||||
|
||||
if ( ! empty( $header_to ) ) {
|
||||
$holder['header_to'] = $header_to;
|
||||
unset( $holder['name'] );
|
||||
}
|
||||
|
||||
return $holder;
|
||||
}
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SparkPost;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
const SLUG = 'sparkpost';
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $connection = null ) {
|
||||
|
||||
$description = sprintf(
|
||||
wp_kses( /* translators: %1$s - URL to SparkPost website. */
|
||||
__( '<a href="%1$s" target="_blank" rel="noopener noreferrer">SparkPost</a> is a transactional email provider that\'s trusted by big brands and small businesses. It sends more than 4 trillion emails each year and reports 99.9%% uptime. You can get started with the free test account that lets you send up to 500 emails per month.', 'wp-mail-smtp' ) .
|
||||
'<br><br>' .
|
||||
/* translators: %2$s - URL to wpmailsmtp.com doc. */
|
||||
__( 'To get started, read our <a href="%2$s" target="_blank" rel="noopener noreferrer">SparkPost documentation</a>.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'br' => true,
|
||||
'a' => [
|
||||
'href' => true,
|
||||
'rel' => true,
|
||||
'target' => true,
|
||||
],
|
||||
]
|
||||
),
|
||||
'https://www.sparkpost.com/',
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-sparkpost-mailer-in-wp-mail-smtp/', 'SparkPost documentation' ) )
|
||||
);
|
||||
|
||||
parent::__construct(
|
||||
[
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/sparkpost.svg',
|
||||
'slug' => self::SLUG,
|
||||
'title' => esc_html__( 'SparkPost', 'wp-mail-smtp' ),
|
||||
'php' => '5.6',
|
||||
'description' => $description,
|
||||
'supports' => [
|
||||
'from_email' => true,
|
||||
'from_name' => true,
|
||||
'return_path' => false,
|
||||
'from_email_force' => true,
|
||||
'from_name_force' => true,
|
||||
],
|
||||
'recommended' => false,
|
||||
],
|
||||
$connection
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the mailer provider options.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
// Do not display options if PHP version is not correct.
|
||||
if ( ! $this->is_php_correct() ) {
|
||||
$this->display_php_warning();
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- 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">
|
||||
<?php if ( $this->connection_options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
|
||||
<input type="text" disabled value="****************************************"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php $this->display_const_set_message( 'WPMS_SPARKPOST_API_KEY' ); ?>
|
||||
<?php else : ?>
|
||||
<input type="password" spellcheck="false"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
|
||||
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
|
||||
/>
|
||||
<?php endif; ?>
|
||||
<p class="desc">
|
||||
<?php
|
||||
$url = 'sparkpost.com';
|
||||
$url = $this->connection_options->get( $this->get_slug(), 'region' ) === 'EU' ? 'eu.' . $url : $url;
|
||||
$url = 'https://app.' . $url . '/account/api-keys';
|
||||
|
||||
printf( /* translators: %s - API Key link. */
|
||||
esc_html__( 'Follow this link to get an API Key from SparkPost: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="' . esc_url( $url ) . '" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Region -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-region" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-radio wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region"><?php esc_html_e( 'Region', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region-us">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region-us"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][region]" value="US"
|
||||
<?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'region' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'US', $this->connection_options->get( $this->get_slug(), 'region' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'US', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region-eu">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-region-eu"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][region]" value="EU"
|
||||
<?php echo $this->connection_options->is_const_defined( $this->get_slug(), 'region' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'EU', $this->connection_options->get( $this->get_slug(), 'region' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'EU', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<?php
|
||||
if ( $this->connection_options->is_const_defined( $this->get_slug(), 'region' ) ) {
|
||||
$this->display_const_set_message( 'WPMS_SPARKPOST_REGION' );
|
||||
}
|
||||
?>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'Select your SparkPost account region.', 'wp-mail-smtp' ); ?>
|
||||
<?php
|
||||
printf(
|
||||
wp_kses(
|
||||
/* translators: %s - URL to Mailgun.com page. */
|
||||
__( '<a href="%s" rel="" target="_blank">More information</a> on SparkPost.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
),
|
||||
'https://www.sparkpost.com/docs/getting-started/getting-started-sparkpost'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\Zoho;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Zoho Options constructor.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/zoho.svg',
|
||||
'slug' => 'zoho',
|
||||
'title' => esc_html__( 'Zoho Mail', 'wp-mail-smtp' ),
|
||||
'disabled' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function display_options() {
|
||||
|
||||
?>
|
||||
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content wp-mail-smtp-clear section-heading">
|
||||
<p>
|
||||
<?php esc_html_e( 'We\'re sorry, the Zoho Mail mailer is not available on your plan. Please upgrade to the PRO plan to unlock all these awesome features.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user